【发布时间】:2020-11-29 12:17:02
【问题描述】:
所以现在我正在尝试创建一个命令,该命令基本上创建了阻止特定用户查看频道的覆盖。我唯一遇到的问题是机器人验证用户是否“拥有”频道的部分。有一些频道是玩家拥有的,它们的角色与频道名称相匹配。
举个例子:
#space-invaders
@Space Invaders OP
代码中的问题是,在尝试将角色转换为字符串时,它没有这样做。所以我需要一个替代方案,但我不知道我还能做什么。
@commands.command()
@commands.has_role("Realm OP")
async def block(self, ctx, user: discord.User):
#channel = await ctx.author.create_dm()
channel = ctx.message.channel
author = ctx.message.author
mentions = [role.mention for role in ctx.message.author.roles if role.mentionable]
channel2 = str(channel.name)
channel = channel2.split('-')
if len(channel2) == 2: # #real-emoji
realm, emoji = channel
else: # #realm-name-emoji
realm, emoji = channel[0], channel[-1]
realmName = realm.replace("-" , " ")
realmName1 = realmName.lower()
rolelist = []
authorRoles = discord.Role.name(author.roles) # Issue here
for role in authorRoles:
rolen = role.lower()
rolelist.append(rolen.mention)
if realmName1 in rolelist:
await ctx.send("true")
else:
await ctx.send("false")
任何建议都会有很大帮助!
【问题讨论】:
标签: python discord.py