JDA.公会会员加入/离开活动 [英] JDA. GuildMemberJoin/LeaveEvent

查看:49
本文介绍了JDA.公会会员加入/离开活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了以下方法,但它们都不起作用.有人知道为什么以及如何解决它吗?

PS:该机器人具有管理员权限.

PS: The bot has admin perms.

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();
    }

默认频道设置

推荐答案

引用 JDA Wiki :

有很多原因可能导致您的事件监听器无法执行,但这是最常见的问题:

There are many reasons why your event listener might not be executed but here are the most common issues:

  1. 您使用了错误的登录令牌?
    如果令牌用于无法访问所需公会的其他机器人,则事件侦听器代码无法运行.
  2. 您的机器人实际上不在行会中吗?
    确保您的漫游器处于在线状态,并且有权访问您要与之交互的资源.
  3. 您从未注册过听众?
    JDABuilder JDA 实例上使用 jda.addEventListener(new MyListener())
  4. 您没有覆盖正确的方法?
    使用 @Override 并查看是否失败.您的方法必须使用在 ListenerAdapter 中定义的正确名称和参数列表.
  5. 您实际上并没有扩展 EventListener ListenerAdapter .
    您的课程应该 使用扩展ListenerAdapter implements EventListener .
  6. 您缺少此事件所需的 GatewayIntent .
    请确保您在 JDABuilder enableIntents(...)以允许接收事件.
  7. 该事件还有其他可能无法满足的要求,例如未启用缓存.
    请检查活动文档上的要求.
  1. 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.
  2. 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.
  3. You never registered your listener?
    Use jda.addEventListener(new MyListener()) on either the JDABuilder or JDA instance
  4. 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 in ListenerAdapter.
  5. You don't actually extend EventListener or ListenerAdapter.
    Your class should either use extends ListenerAdapter or implements EventListener.
  6. You are missing a required GatewayIntent for this event.
    Make sure that you enableIntents(...) on the JDABuilder to allow the events to be received.
  7. 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 意向.

You can enable the GUILD_MEMBERS intent by doing builder.enableIntents(GatewayIntent.GUILD_MEMBERS) on JDABuilder.

例如:

JDABuilder builder = JDABuilder.createDefault(token);
builder.enableIntents(GatewayIntent.GUILD_MEMBERS);
builder.addEventListeners(myListener);
JDA jda = builder.build();

这篇关于JDA.公会会员加入/离开活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆