无法读取未定义discord.js v12的属性“角色”

时间:2020-09-10 14:06:06

标签: discord.js

我希望机器人给反应堆一个角色。但它不起作用。有人知道问题出在哪里吗?我在discord.js v12中编码

if (user.bot) return;

if (reaction.message.partial) await reaction.message.fetch();
if (reaction.partial) await reaction.fetch();

if (user.bot) return;
if (!reaction.message.guild) return;
if (reaction.message.guild.id !== "753289194738024632") return;

if (reaction.message.channel.id === "753290581412937832") {
    const cs = bot.emojis.cache.find(emoji => emoji.name === "csgo");
    const vl = bot.emojis.cache.find(emoji => emoji.name === "valorant");
    const fn = bot.emojis.cache.find(emoji => emoji.name === "fortnite");

    let role = reaction.guild.roles.cache.find(role => role.id === '753290549548679229');
    member.roles.add(role.id);

2 个答案:

答案 0 :(得分:1)

尝试将reaction更改为message

let role = message.guild.roles.cache.find(role => role.id === '753290549548679229');

我认为reaction.guild不是有效函数

答案 1 :(得分:1)

我将其更改为:

if(message.channel.type === 'dm') return message.reply('This command does not work in DMs') //checks if the command wasnt executed in DMs
let role = message.guild.roles.cache.find(role => role.id === '753290549548679229');