【问题标题】:How to make a discord.py bot send a message through the console to a specific channel如何让 discord.py 机器人通过控制台向特定频道发送消息
【发布时间】:2020-07-23 22:53:35
【问题描述】:

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

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

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】:
    1. 您不需要将其注册为 client.event,因为您对 Discord 中发生的事情没有反应,这意味着不需要装饰器。

    2. 我不得不说我很困惑为什么你在channel_entry.get 的整数上使用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。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-19
      • 1970-01-01
      • 2016-05-03
      • 2021-06-22
      • 1970-01-01
      • 2021-06-10
      • 1970-01-01
      • 2022-01-03
      相关资源
      最近更新 更多