我正在尝试创建一个只能由不和谐机器人所有者使用的命令。如果我使用下面应该可以工作的代码,它就会崩溃。
所有推荐都有自己的文件,以使其更清晰。
module.exports = {
name: 'pi',
aliases: [],
category: 'beta',
utilisation: '{prefix}pi',
]
[const userID = '<@654353673513861130>'
if(!message.author === userID)
execute(_client, message) {
message.channel.send(`yooo`);
},
};
答案 0 :(得分:0)
我注意到的一个错误是你提供了带有 <@> 作为字符串的 ID,用这个替换常量
const userID = '654353673513861130';
如果您对为命令制作单独的文件感到困惑,请阅读 this doc
答案 1 :(得分:0)
您不能在 if 语句中包装对象方法(在本例中为 execute
)。 if 语句应该在该方法本身内部。
如果您知道 discord bot 的所有者 ID(654353673513861130
,而不是 <@654353673513861130>
),您可以检查它是否与消息作者的 ID 相同。如果不一样,您可以通过提前 return
ing 停止执行命令。仅当作者是机器人所有者时,此 return
语句之后的任何内容才会运行。检查下面的代码:
module.exports = {
name: 'pi',
aliases: [],
category: 'beta',
utilisation: '{prefix}pi',
execute(_client, message) {
const ownerID = '654353673513861130';
// if the ID is NOT the same, return early to exit
if (message.author.id !== ownerID) return;
// rest of the code is only run if the author is the bot owner
message.channel.send(
`I know you're the owner, ${message.author}. I mean, I know that your discord ID is ${ownerID}`,
);
},
};