我想在向用户添加角色时,机器人将消息发送到文本通道。我该怎么办?
答案 0 :(得分:0)
您必须使用guildMemberUpdate事件。
以下是您如何执行此操作的示例:
const Discord = require('discord.js');
exports.run = async (client, oldMember, newMember) => {
const messagechannel = msg.guild.channels.find('name', 'YOUR NAME OF YOUR CHANNEL');
if (oldMember.roles.size < newMember.roles.size) {
const embed = new Discord.RichEmbed()
.setColor('#FE2E2E')
.setTimestamp()
.setAuthor('Role added!')
.addField(`Member:`, `${oldMember.user.tag} (${oldMember.id})`);
for (const role of newMember.roles.map(x => x.id)) {
if (!oldMember.roles.has(role)) {
embed.addField(`Role:`, `${oldMember.guild.roles.get(role).name}`);
}
}
messagechannel.send({
embed
});
}
}