【问题标题】:Is there any possibility of a python discord bot posting in a specific channel是否有可能在特定频道中发布 python discord bot
【发布时间】:2018-09-22 21:02:05
【问题描述】:

我正在使用 Python 为我们的 Discord-Server 制作一个机器人。 我希望机器人在每次重新启动时将内容发布到特定频道。

我的代码

@client.event 
async def on_ready():
   msg = 'Ready when you are :thumbsup:'
   await client.send_message(message.channel, msg)

我想我必须改变

message.channel

但我不知道怎么做。

【问题讨论】:

    标签: python-3.x discord discord.py


    【解决方案1】:

    on_ready 事件没有message 对象。您必须遍历机器人可以访问的所有频道并在您想要的频道中发布。下面是一个示例,其中机器人将首先遍历client.servers,然后遍历server.channels,然后将msg 发送到每个“通用”channel.name

    @client.event
    async def on_ready():
        msg = 'Ready when you are :thumbsup:'
        for server in client.servers:
            for channel in server.channels:
                if channel.name == 'general':
                    await client.send_message(channel, msg)
    

    【讨论】:

      猜你喜欢
      • 2023-03-27
      • 2020-07-13
      • 2021-03-27
      • 2021-07-06
      • 1970-01-01
      • 2021-08-18
      • 2020-10-01
      • 2021-07-20
      • 2018-12-01
      相关资源
      最近更新 更多