首页 > 解决方案 > Discord 机器人不发送问候消息

问题描述

问题是当新成员加入时,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]});
});

标签: javascriptdiscordbots

解决方案


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

转到Discord Developer Portal并导航到您的应用程序并启用server member意图 Developer Portal > Bot App > Bot > 启用服务器成员意图

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

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

推荐阅读