Java Discord Bot无法发送消息
我正在开发一个discord机器人,但我遇到了一些我从未遇到过的问题。我的discord bot无法发送消息。bot不包含任何不推荐使用的方法。代码如下: 主要内容: TestCommand(用于测试bot是否工作): }Java Discord Bot无法发送消息,java,discord,bots,Java,Discord,Bots,我正在开发一个discord机器人,但我遇到了一些我从未遇到过的问题。我的discord bot无法发送消息。bot不包含任何不推荐使用的方法。代码如下: 主要内容: TestCommand(用于测试bot是否工作): } 谢谢。您禁用了GUILD\u消息。调用createDefault时,将其添加到意图列表中: EnumSet intents=EnumSet.of( GatewayIntent.GUILD_成员,//用于成员加入/删除事件和缓存 GatewayIntent.GUILD_EMOJ
谢谢。您禁用了
GUILD\u消息。调用createDefault
时,将其添加到意图列表中:
EnumSet intents=EnumSet.of(
GatewayIntent.GUILD_成员,//用于成员加入/删除事件和缓存
GatewayIntent.GUILD_EMOJIS,//用于GUILD#getEmotes(不是很有用)
GatewayIntent.GUILD_VOICE_STATES,//用于成员语音国家
GatewayIntent.GUILD_MESSAGES//用于消息接收事件
);
JDA JDA=JDABuilder.createDefault(“My.Token.Here”,意图)
.addEventListeners(新建TestCommand()、新建JoinCommand()、客户端)
.build();
阅读您是否尝试在e.getChannel().sendMessage(“test”).queue()处放置断点
查看是否到达该行?我已经快速查看了API,如果到达该行,您应该使用带有两个参数的可选queue
方法来查看调用是否返回错误:否。当我运行命令时,它没有到达该行,则GuildMessageReceivedEvent
不会发生,或者e.getMessage().getContentRaw().equalsIgnoreCase(“!test”)
从来都不匹配是的,但我看过视频,每个人都这么做。谢谢你是最好的谢谢
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!");
}
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();
}
}