如何使discord.py机器人通过控制台将消息发送到特定频道

问题描述 投票:0回答:1

discord.py - Send messages though console-这个问题已经过时,因此我将尝试重新提问,因为那里提供的解决方案不起作用。

我希望我的不和谐机器人通过控制台中的输入将消息发送到特定频道。我的代码如下:

channel_entry = 614001879831150605
msg_entry = 'test'

@client.event
async def send2():
    channel = client.get_channel(channel_entry.get) 
    await channel.send(msg_entry)

我收到以下错误:

AttributeError: 'NoneType' object has no attribute 'send'

感谢您的任何帮助。

python discord.py
1个回答
0
投票
  1. 您不需要将其注册为client.event,因为您不会对Discord中发生的事情进行反应,这意味着不需要装饰器。

  2. 我不得不说我很困惑,为什么要在get中的整数上使用channel_entry.get。只需单独使用整数。这可能是错误的根源。因为您没有将整数传递给client.get_channel,所以它会返回None对象,因为没有找到通道。 documentation

工作示例:

channel_entry = 614001879831150605
msg_entry = 'test'

async def send_channel_entry():
    channel = client.get_channel(channel_entry) 
    await channel.send(msg_entry)

还要确保您安装了最新版本的discord.py。

© www.soinside.com 2019 - 2024. All rights reserved.