至尊寶的傳說
2022-08-27 13:56:59
我對構建自己的機器人有點陌生,到目前為止,我希望我的用戶能夠使用該命令!訂閱“他們的 ID”,我的機器人將從我的 Web API 中提取信息,并將其分配給他們的角色示例。ID 1 = 高級 ID 2 = 超級高級到目前為止,我已經得到了這個:const request = require('request');request('https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY', { json: true }, (err, res, body) => { if (err) { return console.log(err); } console.log(body.url); console.log(body.explanation);});現在,如果我想分配角色,它會是什么樣子...
1 回答

慕妹3146593
TA貢獻1820條經驗 獲得超9個贊
這就是我根據這個問題想要發生的事情:
用戶:“!子 1“
機器人: * 將用戶分配到角色 1 *
如果這是你想做的,我會這樣繼續:
您需要存儲您的角色 ID,以便以后可以分配它們。也可以使用角色名稱,但需要記住,如果不更新代碼,則無法更改它。
然后,您需要使用
GuildMember.roles.add()
將角色添加到用戶。
下面是一個示例:
// I'll assume that you already have the command structure set up, so these variables will be set:
// - message: The message with the command (its content will be '!Sub 1' in this case)
let role = message.guild.roles.cache.find(r => r.name == 'Premium') // You can use you role's name here
let roleID = '1234...' // This would be your role ID
message.member.roles.add(role || roleID)
這將是添加角色的方法。您只需要根據用戶輸入的內容切換角色名稱/ID,這將是您的第一個參數。
添加回答
舉報
0/150
提交
取消