javascript - 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]});
});
解决方案
看起来您没有为机器人启用“公会成员”意图以检测对公会成员所做的更改
转到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
推荐阅读
- mysql - Slow response in chat messages using cronjob
- php - 在 WooCommerce 管理员订单列表上显示使用过的优惠券
- python - Get ID in Django
- android - error: The method 'setMapStyle' isn't defined for the type 'Completer'
- node.js - Deploy Azure Function with an Alpine - Unhandled 'error' event
- python-3.x - Unable to update PostgrSQL table using psycopg2
- php - Wordpress 403 禁止错误仅适用于特定菜单
- python - 如何从 Python 中的特定字母输出字符串的其余部分?
- c++ - 在 C++ 中的非托管可执行文件中运行托管可执行文件
- python - Alembic env.py 不读取 Flask 项目中的环境变量