【问题标题】:Sending a message to Discord with Python using discord.py使用 discord.py 使用 Python 向 Discord 发送消息
【发布时间】:2020-09-23 19:02:28
【问题描述】:

我正在创建一个可以在线监控内容的机器人,并且我已经完成了代码并在终端中运行。我想使用 discord.py 在 Discord 的频道中打印我的结果,而无需来自 Discord 用户的命令/输入。我只希望我的程序在在线获取产品时向我在 Discord 中的服务器发送一条消息。我该怎么做?

【问题讨论】:

  • 研究使用webhooks。还有docs,以防您有兴趣将其整合到机器人中。

标签: python discord discord.py


【解决方案1】:

您必须从 id 获取频道,然后使用 send 发送。

代码(假设您的客户是client):

channel = client.get_channel(123456789) # get channel from id
await channel.send('message here') # send message

【讨论】:

  • 当我说的时候,它说在异步函数之外等待?
  • @cxiw 你检查产品的代码是什么?
  • 这是我没有找到补货的 else 声明: else: print("NO RESTOCK FOUND...STILL MONITORING") client = commands.Bot(command_prefix='!') channel = client.get_channel( 123456789) 等待 channel.send('NO RESTOCK FOUND')
  • 您可以使用discord.ext.tasks.loop 并将您的检查逻辑放在那里。
猜你喜欢
  • 1970-01-01
  • 2021-06-14
  • 1970-01-01
  • 2021-03-24
  • 1970-01-01
  • 1970-01-01
  • 2021-02-24
  • 2021-03-11
  • 1970-01-01
相关资源
最近更新 更多