本文介紹了Discord python關(guān)于角色授予事件的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
所以我一直試圖讓機(jī)器人在成員獲得角色授予時(shí)宣布,我知道這段代碼可能根本沒(méi)有意義,但這就是為什么我要問(wèn):我該怎么做?
So i've been trying to get the bot to announce whenever a member gets a role granted, i know that this code may not make sense at all, but that's why i'm asking: How could i do it?
@bot.event
async def on_member_update(before, after):
if str(after.roles) == 'android':
fmt = "{0.mention} your role request has been accepted! :confetti_ball: You've been granted the role '{1}'"
await bot.send_message(bot.get_channel('495285593711050754'), fmt.format(member, after.roles.name))
print(colored('moderation.clf: ', 'blue'), colored('Android granted', 'white'))
if str(after.roles) == 'human':
fmt = "{0.mention} your role request has been accepted! :confetti_ball: You've been granted the role '{1}'"
await bot.send_message(bot.get_channel('495285593711050754'), fmt.format(member, after.roles.name))
print(colored('moderation.clf: ', 'blue'), colored('Human granted', 'white'))
if str(after.roles) == 'moderator':
fmt = "{0.mention} you are now part of the CyberLife staff, we're so excited to have you here! :confetti_ball:"
await bot.send_message(bot.get_channel('495285593711050754'), fmt.format(member, after.roles.name))
print(colored('moderation.clf: ', 'blue'), colored('Moderator granted', 'white'))
推薦答案
首先您必須檢查用戶是否獲得了新角色.然后您可以檢查他們獲得的角色是否是您正在尋找的角色之一:
First you have to check that the user got a new role. Then you can check that the role they got is one of the ones you're looking for:
@bot.event
async def on_member_update(before, after):
if len(before.roles) < len(after.roles):
new_role = next(role for role in after.roles if role not in before.roles)
if new_role.name in ('android', 'human'):
fmt = "{0.mention} your role request has been accepted! :confetti_ball: You've been granted the role '{1}'"
await bot.send_message(bot.get_channel('495285593711050754'), fmt.format(after, new_role.name))
elif new_role.name in ('moderator'):
fmt = "{0.mention} you are now part of the CyberLife staff, we're so excited to have you here! :confetti_ball:"
await bot.send_message(bot.get_channel('495285593711050754'), fmt.format(after))
這篇關(guān)于Discord python關(guān)于角色授予事件的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!