【发布时间】:2020-12-03 11:18:50
【问题描述】:
我正在 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' object has no attribute 'send'
提前致谢。
【问题讨论】:
-
您是否尝试过使用
try : except:发送错误消息并尝试恢复执行 -
不,我没试过
-
discordpy.readthedocs.io/en/latest/api.html 显示频道 id 应该是一个 int,但我相信 arg1 在这里是一个字符串。不知道这是否重要,但您可能想尝试将 arg1 转换为 int。
标签: python discord discord.py