Discord Py,通过 ID 在任何频道中发送消息

我得到以下命令:


@client.command()

async def send(ctx, channel, *, content):

    channel = client.get_channel(id)

    await channel.send(content)

设置channel=None不会改变任何东西和错误:


'NoneType' object has no attribute 'send'

async def send(ctx, channel=None, *, content):(不改变任何东西 - 错误保持不变)


示例:我想向我通过 ID 选择的频道发送消息。

图片是命令的截图。


呼唤远方
浏览 140回答 1
1回答

阿晨1998

发生这种情况channel是因为None. 例如:如果您像这样打印频道类型@client.command()async def send(ctx, channel, *, content):&nbsp; &nbsp; channel = client.get_channel(channel)&nbsp; &nbsp; print(type(channel))&nbsp; &nbsp; # await channel.send(content)你的输出将是<class 'NoneType'>。要解决此问题,您可以int像这样传递给频道输出:@client.command()async def send(ctx, channel, *, content):&nbsp; &nbsp; channel = client.get_channel(int(channel))&nbsp; &nbsp; await channel.send(content)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python