discord bot无法发送消息

eeq64g8w  于 2021-07-06  发布在  Java
关注(0)|答案(1)|浏览(763)

我正在开发一个不和谐机器人,但是我遇到了一些我从未遇到过的问题。我的discord机器人无法发送消息。bot不包含任何不推荐使用的方法。代码如下:
主要内容:

private Main() throws LoginException {
    final JDA jda = JDABuilder.createDefault("My.Token.Here", GatewayIntent.GUILD_MEMBERS, GatewayIntent.GUILD_EMOJIS, GatewayIntent.GUILD_VOICE_STATES).build();

    CommandClientBuilder builder = new CommandClientBuilder();
    builder.setOwnerId("778564522046128148");
    builder.setActivity(Activity.watching("es bueda fixe!"));

    CommandClient client = builder.build();

    jda.addEventListener(client);
    jda.addEventListener(new JoinLeave());
    jda.addEventListener(new TestCommand());
}

public static void main(String[] args) throws LoginException{
    long enable = System.currentTimeMillis();
    new Main();
    System.out.println("Bot enabled in: " + (System.currentTimeMillis() - enable) + "ms!");
}

testcommand(测试bot是否工作):

public class TestCommand extends ListenerAdapter {

@Override
public void onGuildMessageReceived(GuildMessageReceivedEvent e){
    System.out.println("hefdfs");
    if(e.getMessage().getContentRaw().equalsIgnoreCase("!test")){
        e.getChannel().sendMessage("test").queue();
    }
}

}
谢谢。

xzlaal3s

xzlaal3s1#

您禁用了 GUILD_MESSAGES 意图。打电话的时候把它加到你的意图清单上 createDefault :

EnumSet<GatewayIntent> intents = EnumSet.of(
  GatewayIntent.GUILD_MEMBERS, // for member join/remove events and cache
  GatewayIntent.GUILD_EMOJIS, // for Guild#getEmotes (not very useful)
  GatewayIntent.GUILD_VOICE_STATES, // for member voice states
  GatewayIntent.GUILD_MESSAGES // for message received event
);
JDA jda = JDABuilder.createDefault("My.Token.Here", intents)
                    .addEventListeners(new TestCommand(), new JoinCommand(), client)
                    .build();

读取网关意图和成员缓存

相关问题