我在Discord.py上制作了一个漫游器,并尝试设置要使用自变量发送消息的通道。 代码是这样的:
@client.command()
async def send(ctx, arg1):
channel = client.get_channel(arg1)
await channel.send('Message')
当我键入通道ID而不是arg1时,它可以工作,但是当我在Discord上键入命令时(!send 282772187812),它不起作用,并且出现以下错误:discord.ext.commands.errors.CommandInvokeError:命令引发异常:AttributeError:'NoneType'对象没有属性'send'
谢谢。
答案 0 :(得分:0)
正如@backcab所说,您可以将arg1
转换为整数,也可以使用ext.commands中的通道转换器。
解决方案1
@client.command()
async def send(ctx, arg1):
channel = client.get_channel(int(arg1))
await channel.send('Message')
解决方案2
@client.command()
async def send(ctx, channel: discord.TextChannel):
await channel.send('Message')