- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我编写了以下方法,但它们都不起作用。有人知道为什么以及如何解决它吗?
PS:该机器人具有管理员权限。
public class GuildMemberJoin extends ListenerAdapter {
public void onGuildMemberJoin(GuildMemberJoinEvent event) {
EmbedBuilder join = new EmbedBuilder();
join.setColor(Color.getHSBColor(227, 74, 64));
join.setTitle("SERVER UPDATE");
join.setDescription(event.getMember().getAsMention() + " has now joined The server!");
event.getGuild().getDefaultChannel().sendMessage(join.build()).queue();
}
public class GuildMemberLeave extends ListenerAdapter {
public void onGuildMemberLeave(GuildMemberLeaveEvent event) {
EmbedBuilder join = new EmbedBuilder();
TextChannel spamChannel = event.getGuild().getTextChannelById("713429117546135572");
join.setColor(Color.getHSBColor(227, 74, 64));
join.setTitle("SERVER UPDATE");
join.setDescription(event.getMember().getAsMention() + " has now left the server!");
spamChannel.sendMessage(join.build()).queue();
}
默认 channel 设置
最佳答案
引用JDA Wiki :
There are many reasons why your event listener might not be executed but here are the most common issues:
- You are using the wrong login token?
If the token is for another bot which doesn't have access to the desired guilds then the event listener code cannot run.- Your bot is not actually in the guild?
Make sure your bot is online and has access to the resource you are trying to interact with.- You never registered your listener?
Usejda.addEventListener(new MyListener())
on either theJDABuilder
orJDA
instance- You did not override the correct method?
Use@Override
and see if it fails. Your method has to use the correct name and parameter list defined inListenerAdapter
.- You don't actually extend
EventListener
orListenerAdapter
.
Your class should either useextends ListenerAdapter
orimplements EventListener
.- You are missing a required
GatewayIntent
for this event.
Make sure that youenableIntents(...)
on theJDABuilder
to allow the events to be received.- The event has other requirements that might not be satisfied such as the cache not being enabled.
Please check the requirements on the event documentation.If none of the above apply to you then you might have an issue in your listener's code, at that point you should use a debugger.
澄清:
您可以通过在 JDABuilder
上执行 builder.enableIntents(GatewayIntent.GUILD_MEMBERS)
来启用 GUILD_MEMBERS
意图。
例如:
JDABuilder builder = JDABuilder.createDefault(token);
builder.enableIntents(GatewayIntent.GUILD_MEMBERS);
builder.addEventListeners(myListener);
JDA jda = builder.build();
关于java - JDA。公会成员加入/离开事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62267453/
制作一个不和谐的机器人。一切工作正常,除了 -!prefix 的一个命令。 -! 是前缀,命令采用参数并更改服务器的前缀。 在我详细讨论这个 while 事情之前,这是机器人的代码,也许我只是在 co
我将 Discord OAuth2 用于我的 Discord 机器人仪表板。我通过链接检索用户的服务器 https://discord.com/api/users/@me/guilds .我想提示用户
我是一名优秀的程序员,十分优秀!