TypeError:message.guild.roles.find不是函数 [英] TypeError: message.guild.roles.find is not a function

查看:65
本文介绍了TypeError:message.guild.roles.find不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码

client.on('message', message => {
    if (message.content.startsWith(`${prefix2}red`)){
    if (message.member.roles.cache.some(role => role.name === 'Red')) return message.channel.send(`You already have the role!`)
    let role = message.guild.roles.find(r => r.name === "Red");(r => r.name === "Red");
    let member = message.member;
    message.delete(1)
    member.addRole(role).catch(console.error)
    }   
})

我正在尝试执行以下命令将赋予用户该角色。

错误

I am trying to make a command that will give the user that role.
Error:

let role = message.guild.roles.find(r => r.name === "Red");
                                       ^

TypeError: message.guild.roles.find is not a function


推荐答案

使用 message.guild.roles.cache.find

这篇关于TypeError:message.guild.roles.find不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆