简体   繁体   English

如何在 discord.js v12 中创建角色特定命令

[英]How can i make a role specific command in discord.js v12

I've been searching and tried pasting and modifying about everything on this website but here goes:我一直在搜索并尝试粘贴和修改此网站上的所有内容,但这里是:

client.on("message", (message) => {
    if (message.content == "?status on") {
        if (message.author.roles.has(578319894039232558)) client.user.setActivity(`0.4.4 | ?help | being cool`);
    }
});

I want to make only the owner of the server be able to turn the status from boot (none) to turning on no matter what I try it cant make role-specific.我只想让服务器的所有者能够将状态从启动(无)变为打开,无论我尝试什么,它都无法使角色特定。

message.author returns a User object, which has no roles property. message.author返回一个没有roles属性的User object。

You are looking for message.member which returns a GuildMember object.您正在寻找返回GuildMember object 的message.member

Another mistake I spotted is that you need to use strings for IDs.我发现的另一个错误是您需要使用字符串作为 ID。 Why?为什么?


Discord JS Version 12+ Discord JS版本12+

client.on("message", (message) => {
    if (message.content == "?status on") {
        if (!message.member.roles.cache.has("578319894039232558")) return false;
        client.user.setActivity(`0.4.4 | ?help | being cool`);
    }
});

Discord JS Version 11 Discord JS版本11

client.on("message", (message) => {
    if (message.content == "?status on") {
        if (!message.member.roles.has("578319894039232558")) return false;
        client.user.setActivity(`0.4.4 | ?help | being cool`);
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM