试图创建一个on_message事件,其中多个角色可以使用该命令。当我把FO, GM, HC, AC这样的个人角色放在一起的时候它是有效的但是当我把他们都放在那里作为员工角色的时候;没有响应
if "sign" in message.content:
signer=message.author
signee=message.mentions[0].mention
signeeid=message.mentions[0].id
server=bot.get_guild(782690561135083551)
teamsidslist=[782730424093769748, 788549127499153459, 787889904465215519, 786747382905176074, 783495172117102654, 788872681184952360, 782997813947531315, 782750341850333245, 800268209420369951, 788579996184477697, 788902115849666621, 799668339881672734, 788587247951675422, 783151342293745705]
teamnames=['Detroit Lions', 'Los Angeles Rams', 'Seattle Seahawks', 'Cleveland Browns', 'Pittsburgh Steelers', 'Buffalo Bills', 'Atlanta Falcons', 'San Francisco 49ers', 'Arizona Cardinals', 'Green Bay Packers', 'Indianapolis Colts', 'New Orleans Saints', 'Tennessee Titans', 'Jacksonville Jaguars']
teamemojis=['Detroit_Lions', 'Los_Angeles_Rams', 'Seattle_Seahawks', 'Cleveland_Browns', 'Pittsburgh_Steelers', 'Buffalo_Bills', 'Atlanta_Falcons', 'Green_Bay_Packers', 'Indianapolis_Colts', 'New_Orleans_Saints', 'Tennessee_Titans', 'Jacksonville_Jaguars']
FO = discord.utils.get(message.author.guild.roles, id=782730552037081128)
GM = discord.utils.get(message.author.guild.roles, id=802169554880692275)
HC = discord.utils.get(message.author.guild.roles, id=802169838205796352)
AC = discord.utils.get(message.author.guild.roles, id=802169983088984094)
staffroles = [FO, GM, HC, AC]
FA = discord.utils.get(message.author.guild.roles, id=782711892577615883)
Suspended = discord.utils.get(message.author.guild.roles, id=804363507842940948)
roster=[]
agency=[]
teams=[]
for rolesids in message.author.roles:
if rolesids.id in teamsidslist:
teams.append(rolesids.id)
step2=str(teams)
step3=step2.replace("[","")
step4=step3.replace("]","")
print(step4)
step5=teamsidslist.index(int(step4))
print(step5)
emote=discord.utils.get(server.emojis,name=teamemojis[step5])
teamname=teamnames[step5]
team = discord.utils.get(message.author.guild.roles,id=int(step4))
for agents in server.members:
if FA in agents.roles:
agency.append(agents.id)
if signeeid not in agency:
embedno = discord.Embed(title="Transaction Failed!", description=None, color=discord.Color.red())
embedno.add_field(name="This Transaction Couldn't Be Completed.", value="This player is signed already! Have them demand from their team or get released.")
await message.channel.send(embed=embedno)
elif staffroles in message.author.roles:
for guys in server.members:
if guys.id==signeeid:
await guys.add_roles(team)
await guys.remove_roles(FA)
if Suspended in guys.roles:
await message.channel.send("This player is signable, but is ineligible as they are suspended.")
roster.append(guys)
roster_size=str(len(roster))
SignEmbed= discord.Embed(title="VFFL Transactions", description=None, color=discord.Color.green())
SignEmbed.add_field(name='Successful Transaction.', value=signee+" has been signed to the "+str(emote)+" "+teamname+"!")
SignEmbed.add_field(name="Roster Size is now ", value=roster_size+'/24', inline=True)
await message.channel.send(embed=SignEmbed)
await bot.process_commands(message)
这一行:
elif staffroles in message.author.roles:
您正在检查message.author.roles
中是否存在人员角色的整个列表,我假设您想测试是否有任何消息作者的角色在人员角色中?
any(role in staffroles for role in message.author.roles)
这一行检查作者拥有的任何角色是否在staffroles列表中。如果至少有一个这样的角色,它返回true
。