【问题标题】:discord.js bot reply if user has a specific role如果用户具有特定角色,discord.js 机器人会回复
【发布时间】:2021-10-08 10:06:12
【问题描述】:

我需要我的机器人回复特定角色,如果用户没有该角色,机器人回复另一条消息“不允许执行此命令”这是我的代码:

client.on("message", (message) => {
    // Command handler, seen previously
    if (message.content === "#سرقة") {
        let frole = message.guild.roles.cache.get("861336755197575178");

        if (frole) return message.channel.send("u are not allowed to use this command");

        message.reply("يرجى تحديد نوع السرقة");
        message.channel.send(" -بقالة");
        message.channel.send("-محل ملابس");
        message.channel.send("-البنك المركزي");
    }
});

【问题讨论】:

  • StackOverflow 不是代码编写服务。您是否尝试过寻找方法来检查成员是否具有特定角色?

标签: javascript node.js discord discord.js


【解决方案1】:

您可以使用GuildMemberRoleManager#cache.has() 来确定@​​987654323@ 是否有Role


client.on("message", (message) => {
    if (message.content === "#سرقة") {
        if (message.member.roles.cache.has("861336755197575178")) {
            message.reply("You are allowed to use this command.");
        } else {
            message.channel.send("You are not allowed to use this command.");
        }
    }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-25
    • 2020-12-25
    • 1970-01-01
    • 2020-09-21
    • 2023-03-03
    • 1970-01-01
    相关资源
    最近更新 更多