【问题标题】:Discord.js v12 problem with a reaction messageDiscord.js v12 出现反应消息问题
【发布时间】:2020-11-30 01:26:00
【问题描述】:

我正在尝试发布一条消息,让用户能够做出反应并获得角色。我收到一个错误Cannot read property 'cache' of undefined。定义了 channelid 和角色名称。

我的代码:

    if(blueroleID !== 0) {
    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.channel.id === channelid){}
    if (reaction.emoji.name === "????") {
        await reaction.message.members.cache.get(user.id).roles.add(rolename)
    }
}}) ```

【问题讨论】:

  • 每条消息只有一个member - 消息的作者。也许您打算改用reaction.users.cache

标签: discord.js


【解决方案1】:

discord.js Message 类没有 members 属性。但是可以使用事件侦听器的第二个参数中的User 对象。它是一个用户对象,但可以使用Guild.member(User) 解析为GuildMember 对象。因此,您可以使用以下代码:

await reaction.message.guild.member(user).roles.add(rolename)

【讨论】:

    猜你喜欢
    • 2021-01-03
    • 2021-11-13
    • 2020-12-22
    • 2020-12-10
    • 2020-10-25
    • 1970-01-01
    • 2021-03-31
    • 2022-01-21
    • 2021-11-02
    相关资源
    最近更新 更多