【问题标题】:Discord bot doesn't send a greeting messageDiscord 机器人不发送问候语
【发布时间】:2021-11-17 23:49:51
【问题描述】:

问题是当有新成员加入时,Discord bot 不会发送问候消息。

节点版本为 16

discord.js 是 v13

终端没有显示错误。 这是代码:


bot.on('ready', () =>{
    console.log('This bot is online!');
})

bot.on('guildMemberAdd', guildMember=>{
    const User = guildMember.user
        const channel = guildMember.guild.channels.cache.find(channel => channel.id == '798928691988004897');
        
        console.log(User)
    
        const embed = new Discord.MessageEmbed()
            .setColor('#0099ff')
            .setTitle('Welcome')
            .setDescription(`Welcome to the server <@${User.id}>`)
            .setThumbnail(`${User.avatarURL()}`)
        
            channel.send({embeds :[embed]});
});

【问题讨论】:

    标签: javascript discord bots


    【解决方案1】:

    您似乎没有为机器人启用“公会成员”意图来检测对公会成员所做的更改

    转到Discord Developer Portal 并导航到您的应用程序并启用server member 意图

    您还需要在代码中启用此意图

    const { Intents, Client } = require('discord.js'); // require other classes as per your bot needs
    const intents = [Intents.FLAGS.GUILD_MEMBERS]; // Add other related intents
    const bot = new Client({ intents: intents });
    
    // finish your code with events and stuff
    

    【讨论】:

    • 所以它会是这样的:const { Intents, Client } = require('discord.js'); const bot = new Client({ intents: intents }); const Discord = require('discord.js') const bot = new Discord.Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MEMBERS] });@EJBEAN 对吧?
    • 我已经声明了bot常量,你不需要再声明了
    • {intents: intents} 是不需要的。只需输入{ intents }
    猜你喜欢
    • 2021-06-18
    • 2021-08-19
    • 2020-11-23
    • 2021-01-08
    • 2020-04-02
    • 2018-12-05
    • 2021-08-02
    • 2021-02-22
    • 2019-09-12
    相关资源
    最近更新 更多