简体   繁体   English

Discord.py 角色

[英]Discord.py roles

I want to send message if the author has the role, but if I try this code it doesn't work (id of role is right).如果作者有角色,我想发送消息,但是如果我尝试此代码,则它不起作用(角色 ID 是正确的)。

@client.command()
async def role(ctx):
    roles = ctx.author.roles
    for x in roles:
        if x.id == '850644250152665098':
await ctx.send("Role")

discord.Role.id returns an integer value. discord.Role.id返回一个整数值。 That means that you cannot compare it with a string.这意味着您不能将其与字符串进行比较。 All you have to do is change if x.id == '850644250152665098': to if x.id == 850644250152665098: .您所要做的就是将if x.id == '850644250152665098':更改为if x.id == 850644250152665098:

You are comparing a str to an int in addition to that the last line is not indented well除了最后一行缩进不好之外,您正在将strint进行比较

@client.command()
async def role(ctx):
    for role in ctx.author.roles:
        if role.id == 850644250152665098:
            await ctx.send(f"Role {role.name} has been found")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM