[英]Discord.js if user has role?
I need help with my bot.我的机器人需要帮助。 My bot should only respond if a user has a specific role.只有当用户具有特定角色时,我的机器人才会响应。 It should be definable by name and not by ID.它应该可以通过名称而不是 ID 来定义。 I user Discord.js 12.0.2我用户 Discord.js 12.0.2
my code我的代码
//DBD embed
client.on("message", async message => {
let cmd = message
if (message.content === '/code-embed') {
message.channel.send("Der angefragte Bot code", { files: [ "./dbd/embed.txt" ] })
}})
you can use some()
on the roles
collection of the GuildMember
to check if they have a specific role.您可以在GuildMember
的roles
集合上使用some()
来检查它们是否具有特定角色。
if (!message.member.roles.cache.some((role) => role.name === 'RoleName')) return
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.