本文介紹了Discord python關于角色授予事件的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
所以我一直試圖讓機器人在成員獲得角色授予時宣布,我知道這段代碼可能根本沒有意義,但這就是為什么我要問:我該怎么做?
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))
這篇關于Discord python關于角色授予事件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!