简体   繁体   English

我正在使用 JDA 4.1.1_110 并且我的 Discord Bot 无法在频道中发送消息

[英]I'm using JDA 4.1.1_110 and my Discord Bot is unable to send message in the channel

I'm using JDA 4.1.1_110, here is my code, i have used ListenerAdapter to listen to event,我正在使用 JDA 4.1.1_110,这是我的代码,我使用 ListenerAdapter 来监听事件,

    import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
    import net.dv8tion.jda.api.hooks.ListenerAdapter;

    public class Commander extends ListenerAdapter {
    public void onMessageReceieved(MessageReceivedEvent event) {
        String[] args = event.getMessage().getContentRaw().split("\\s+");
        if(args[0].equalsIgnoreCase(EmbedBot.prefix+"info")) {
            event.getChannel().sendTyping().queue();
            event.getChannel().sendMessage("Hello").queue();
        }

I have also registered this class in my bot's main class,我也在我的机器人的主类中注册了这个类,

import javax.security.auth.login.LoginException;
import net.dv8tion.jda.api.AccountType;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.OnlineStatus;
import net.dv8tion.jda.api.entities.Activity;

public class EmbedBot {
public static JDA jda;
public static String prefix = "$";
public static void main(String args[]) throws LoginException {
jda = new 
JDABuilder(AccountType.BOT).setToken("the token i can't show").build();
jda.getPresence().setStatus(OnlineStatus.ONLINE);
jda.getPresence().setActivity(Activity.listening("Rohan"));
jda.addEventListener(new Commander());
   }
}

Now on typing "$info" on #general channel in my Test Server, I am not getting any response from the bot, the bot shows all the features like Online Status and the "Listening to Rohan" activity but it isn't sending any message.现在,在我的测试服务器的 #general 频道上输入“$info”时,我没有收到机器人的任何响应,机器人会显示所有功能,例如在线状态和“聆听 Rohan”活动,但它没有发送任何信息。 I have made sure that the bot has all permissions to send messages and I have checked the #general channel's role permissions too.我已确保机器人具有发送消息的所有权限,并且我也检查了 #general 频道的角色权限。 The bot has all the permissions to send messages but it isn't sending when i type "$info".机器人拥有发送消息的所有权限,但当我输入“$info”时它没有发送。

I think you have to write about the onMessageReceieved Event @Override.我认为您必须写下 onMessageReceieved 事件 @Override。 I'm not sure..我不知道..

Otherwise, maybe see if the bot has the permissions否则,也许看看机器人是否有权限

You are using a deprecated class.您正在使用已弃用的类。

Use this syntax to initialize:使用此语法进行初始化:

JDA jda=JDABuilder.createDefault("ur token").addEventListeners(new Commander()).build();

And in commander use onGuildMessageReceived.在指挥官中使用 onGuildMessageReceived。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM