机器人检查 ctx.channel 的名称是否在给定列表 discord.py 中
Bot checking if the name of ctx.channel is in a given list discord.py
我编写了以下代码:
@client.event
async def on_message(ctx):
if '?' in ctx.content and ctx.author != client.user.id and ['cmd', 'bot', 'command'] in ctx.channel.name:
print(f'runned by {ctx.author}')
await ctx.channel.send('yup definently worked')
问题是机器人不会检查列表,因为 ['cmd', 'bot', 'command']
需要 string
作为左操作数,而不是 list
。
有办法改变吗?
为什么不反过来比较呢?
if ctx.channel.name in ['cmd', 'bot', 'command']
编辑:
if any(ctx.channel.name in ['cmd', 'bot', 'command']
PS: on_message
不以 ctx
作为参数,它以 message
我编写了以下代码:
@client.event
async def on_message(ctx):
if '?' in ctx.content and ctx.author != client.user.id and ['cmd', 'bot', 'command'] in ctx.channel.name:
print(f'runned by {ctx.author}')
await ctx.channel.send('yup definently worked')
问题是机器人不会检查列表,因为 ['cmd', 'bot', 'command']
需要 string
作为左操作数,而不是 list
。
有办法改变吗?
为什么不反过来比较呢?
if ctx.channel.name in ['cmd', 'bot', 'command']
编辑:
if any(ctx.channel.name in ['cmd', 'bot', 'command']
PS: on_message
不以 ctx
作为参数,它以 message