gpt4 book ai didi

javascript - (discord.js) 我怎样才能让这个命令只适用于某些 Angular 色/用户?

转载 作者:行者123 更新时间:2023-12-05 04:36:33 24 4
gpt4 key购买 nike

在软件开发方面,我仍然相当无能,需要一些帮助才能使此命令仅适用于我的 discord 服务器上的某些 Angular 色,或仅适用于某些用户

client.on('message', async message => {
if (message.content === '-fruits') {
try {
await message.react('🍎');
await message.react('🍊');
await message.react('🍇');
} catch (error) {
console.error('One of the emojis failed to react:', error);
}
}
});

最佳答案

您可以通过创建用户 ID 数组将命令限制为特定用户,如果消息作者 ID 在列表中,则检查它是否与任何命令匹配。

// Create an array of user ids
const adminIDs = [/* List of user IDs */]

client.on('message', async message => {
// Check if the user who sent the message is in the list
if (adminIDs.include(message.author.id)) {
// If user is in list, then check if message matches a command
if (message.content === 'foo') {
// do stuff...
} else if (message.content === 'bar') {
// do more stuff..
  }
}
});

关于 Angular 色,您可以检查用户是否具有特定 Angular 色。

client.on('message', async message => {
// Check if the user has a role with the name "Admin"
if (message.member.roles.find(r => r.name === 'Admin')){
if (message.content === 'foo') {
// do stuff...
} else if (message.content === 'bar') {
// do more stuff..
}
}
});

关于javascript - (discord.js) 我怎样才能让这个命令只适用于某些 Angular 色/用户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70812006/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com