【问题标题】:How to get a bot to send a message automatically?如何让机器人自动发送消息?
【发布时间】:2020-10-22 05:51:26
【问题描述】:

我有一个问题;那是关于如何让 discord.py 机器人在 on_ready(): 上自行发送消息? 它仅在一台服务器中,目前无论哪个频道都无所谓,我在文档中找不到任何内容- 任何帮助表示赞赏^^!

【问题讨论】:

    标签: python discord.py discord.py-rewrite


    【解决方案1】:

    尝试:

    @client.event
    async def on_ready():
       await client.get_channel("enter channel id here").send("bot is online")
    

    【讨论】:

      【解决方案2】:

      我不相信on_ready 对象有权发送。所以我认为通过on_ready 对象是不可能的。您必须通过不同的操作来设置它。

      【讨论】:

      • 这是一个正确的事件,但如果您获取如上所示的可发送,它应该是 gucci
      【解决方案3】:

      你可以这样做:

      Sendchannel = channel Id
      
      @bot.event
      async def on_ready():
        channel = bot.get_channel(Sendchannel)
        await channel.send(“text”)
      

      欲了解更多信息,请查看 12:50 的 this YouTube video(YouTube 视频不是实时的)

      【讨论】:

        猜你喜欢
        • 2022-01-03
        • 2017-05-11
        • 1970-01-01
        • 2021-08-07
        • 2020-12-26
        • 2021-05-30
        • 2022-01-23
        • 2020-10-20
        • 2019-09-19
        相关资源
        最近更新 更多