即使启用了意图,guildMemberAdd 事件也不起作用。 (discord.js)

时间:2021-01-09 02:58:18

标签: discord.js

我正在尝试在我的不和谐机器人上设置欢迎消息功能,但无论我做什么,机器人似乎都无法使用 guildMemberAdd。我知道有新的更新,并按照建议我在 Private Giveaway Intents 下打开了这两个选项。但它仍然不起作用。这是我的代码:

client.on('guildMemberAdd', member => {
    const emb = new MessageEmbed()
          .setColor('#FFBCC9')
          .setTitle("new member")
          .setDescription("welcome to the server!")
    member.guild.channels.get('780902470657376298').send(emb);
});

我也在网上找到了一个建议使用这个的答案:

const { Client, Intents } = require("discord.js");

const client = new Discord.Client({ ws: { intents: new Discord.Intents(Discord.Intents.ALL) }});

但不管我怎么写,除非我使用括号中没有任何内容的 const client = new Discord.Client();,否则我的机器人根本不会上线。

2 个答案:

答案 0 :(得分:1)

随着 v12 的出现,为了获得完整的频道列表,您只能在服务器中获取缓存的频道。因此,为什么您应该更改此行:

member.guild.channels.get('780902470657376298').send(emb);

到:

member.guild.channels.cache.get('780902470657376298').send(emb);

答案 1 :(得分:0)

您错误地传入了意图参数。这是正确的做法。


const { Client, Intents } = require("discord.js");

const client = new Discord.Client({ ws: { intents: ['GUILDS', 'GUILD_MESSAGES', 'GUILD_MEMBERS', 'GUILD_PRESENCES'] } });

如果你使用它,guildMemberAdd 事件将发出。

确保您在开发者门户中打开了意图。如图所示https://i.imgur.com/WfBLtXY.png