在軟體開發方面我仍然相當無能,并且需要一些幫助才能使此命令僅適用于我的不和諧服務器上的某些角色,或者僅適用于某些用戶
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);
}
}
});
uj5u.com熱心網友回復:
您可以通過創建用戶 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..
}
}
});
至于角色,您可以檢查用戶是否具有特定角色。
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..
}
}
});
uj5u.com熱心網友回復:
評論@KyleRifqi 的回答(我沒有 50 個代表。)
角色也有 ID,所以message.member.roles.find(r => r.id === "Role ID string")如果你碰巧有多個同名角色,你可以這樣做
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/418663.html
標籤:
上一篇:如何將新影像拼接到與要洗掉的影像所在位置相同的陣列中并顯示此影像
下一篇:更新事件后添加多個文本區域
