【发布时间】:2021-05-22 11:08:22
【问题描述】:
我想结合 GCP Cloud Scheduler 和 Cloud Functions 每周向 Discord 频道发送消息。
理想情况下,调度程序将使用 HTTP 触发器,然后云函数将运行,将消息发送到特定通道。
main.py:
import discord
def bot_function():
client = discord.Client()
channel_id = "CHANNEL_ID"
@client.event
async def on_ready():
await client.get_channel(channel_id).send("TEST MESSAGE")
client.run("API_KEY")
我在 requirements.text 中包含了不和谐,但是,我在测试函数时遇到了以下错误: error messages:
- RuntimeError:线程 'ThreadPoolExecutor-0_0' 中没有当前事件循环。,
- RuntimeError: set_wakeup_fd 仅在主线程中有效
- TypeError: bot_function() 接受 0 个位置参数,但给出了 1 个
【问题讨论】:
-
你可以在 python 中使用 requests 向 discord 的 API 发送 HTTP 请求来代替发送消息
标签: python google-cloud-functions discord.py google-cloud-scheduler