我正在编写一个不和谐的机器人,但我遇到了一个问题,我对此很陌生,我正在努力学习。 我正在努力让这条欢迎信息发挥作用,但它不会,有什么想法吗?
const Discord = require('discord.js');
const client = new Discord.Client();
const token = "HIDDEN";
const rules = " Coming Soon ";
var prefix = "/";
client.on('ready', () => {
console.log("Azorf is online!");
});
client.on('guildMemberAdd', member => {
let embed = new Discord.MessageEmbed()
.setDescription(':tada: **' + member.user.username + '** joined ' + member.guild.name)
.setFooter('We are now ' + member.guild.memberCount)
member.guild.channels.get('822024147202080771').send(embed)
});
client.on('message', message => {
if (message.author.bot) return;
if (message.content.toLowerCase() === '/rules') {
const embed = new Discord.MessageEmbed()
embed.setColor('#bd0000');
embed.setTitle("Server Rules");
embed.addField("These are the rules of the server:", rules);
message.channel.send({embed});
}
});
client.login(token);
答案 0 :(得分:1)
这个问题是由于当您没有在 Discord Developer Portal 中启用成员意图时 guildMemberAdd 没有触发,您也可以通过手动发出 guildMemberAdd 事件来解决您的事件。
if (message.content.toLowerCase() === '/join') {
client.emit('guildMemberJoin', message.member)
}