【问题标题】:Discord.js Bot Welcomes Member, Assign a Role and send them a DMDiscord.js 机器人欢迎会员,分配角色并向他们发送 DM
【发布时间】:2021-02-20 15:31:33
【问题描述】:

所以当一个新成员加入Guild [discord 服务器]。 Bot应该在某个频道(ID = 766716351007686696)中发送消息,向他们发送直接消息,然后添加角色(人豆)。这是我现在拥有的代码,它不起作用,底部有错误

client.on('guildMemberAdd', member =>{
    const channel = message.guild.channels.cache.find(c => c.id === "766716351007686696")
    const channelwelcomeEmbed = new Discord.MessageEmbed()
        .setColor('#ffd6d6')
        .setTitle('Welcome!')
        .setDescription(`${member} just joined the discord! Make sure to read #rules!`)
        .setTimestamp();
    channel.send(channelwelcomeEmbed);
    const dmwelcomeEmbed = new Discord.MessageEmbed()
        .setColor('#ffd6d6')
        .setTitle('Welcome!')
        .setDescription("For Help Using @Pro Bot#7903, Send The Command `!help` In Server")
        .setTimestamp();
    member.send(dmwelcomeEmbed);
    let role6 = message.guild.roles.cache.find(role => role.name == "Human Bean"); //BASIC ROLE, EVERYONE GETS IT
    if(!role6) return message.reply("Couldn't find that Role .")
    member.roles.add(role6);
});

错误信息是;

    const channel = message.guild.channels.cache.find(c => c.id === "766716351007686696")
                    ^

ReferenceError: message is not defined

【问题讨论】:

    标签: javascript discord discord.js roles


    【解决方案1】:

    修复:const channel = member.guild.channels.cache.get('CHANNEL ID')

    您需要使用member 而不是message。因为guildMemberAdd函数使用member

    client.on('guildMemberAdd', member => {

    【讨论】:

      【解决方案2】:

      您的代码看起来不错,问题是事件没有被触发。那是因为不和谐默认关闭了“特权意图”。

      由于数据的敏感性,某些意图被定义为“特权”。这些意图是:

      • GUILD_PRESENCES
      • GUILD_MEMBERS

      其中一个影响就是您正在经历的事情,即不工作的guildMemberAdd 事件。

      好消息是您可以通过一个简单的步骤解决此问题。只需在discord developer portal 中启用Privileged Gateway Intents,它应该可以正常工作。

      如果您想了解更多信息

      【讨论】:

      • 好的,现在事件被触发了。但是出现错误,详情见帖子底部
      • 是的,您无法访问此事件中的消息。将 message 更改为 member。而且您也无法在活动中回复。如果role6 不存在,则返回。
      猜你喜欢
      • 2021-05-10
      • 1970-01-01
      • 2021-03-03
      • 2021-11-13
      • 2021-02-22
      • 2020-09-14
      • 2021-01-06
      • 2021-06-01
      • 2021-01-22
      相关资源
      最近更新 更多