javascript - 当我对消息做出反应时,机器人不会赋予角色
问题描述
没有错误,但当我对我编码的消息做出反应时,它没有发挥作用。实际上我在 Top.gg 服务器上问过这个问题,但 1 人告诉我我的“命令处理程序”不支持功能。
代码在这里
const { MessageEmbed, Client, Message, Discord } = require('discord.js');
module.exports = {
name: 'rectrole',
description: "If anyone reacts to msg gains role.",
async execute(msg, args, Discord, Client){
const Role = msg.guild.roles.cache.find(role => role.name === "Member");
const channel = '878990757615247410';
const Emoji = '878990351753429073';
const reactionchannel = msg.channel
const reactionEmbed = new MessageEmbed()
.setColor('#ffffff')
.setTitle('REACT TO GET ROLE')
.setDescription('Reacting for get role is important for u to be verified.');
const embed = await reactionchannel.send({ embeds: [reactionEmbed] });
embed.react(Emoji)
Client.on('messageReactionAdd', async (reaction, user) => {
if(reaction.msg.partial) await reaction.msg.fetch();
if(reaction.partial) await reaction.fetch();
if(user.bot) return;
if(!reaction.msg.guild) return;
if(reaction.msg.channel.id == channel){
if(reaction.Emoji.id === Emoji){
await reaction.guild.members.cache.get(user.id).roles.add(Role);
}
}
});
}
}
解决方案
推荐阅读
- java - Jsoup Login in to website仅返回html的头部
- mysql - 在不使用子查询的情况下为 CREATE VIEW 重新构造查询?
- sql - 用“-”分隔列(用于 xml 路径)
- powershell - 使用 PowerShell 解析 Win32 可执行输出
- pandas - 在df python中动态创建列
- python - autoAugment 函数的返回
- python - 参数化 kusto 函数的异常输入
- c# - 我可以在 c# 上创建一些具有动态名称的组件吗?
- arrays - 沿对角线移动(可能是非正方形)二维数组的每个元素
- xml - 使用 UDF 从 PySpark Dataframe 解析 XML 列