python - (Discord.py) 使用 on_guild_join 事件为 dm 消息添加延迟
问题描述
我拥有一个大型不和谐服务器,在我的机器人发布后,每个人都在几秒钟内添加了它。我的机器人的功能之一是对所有者说“感谢您邀请我,输入 -help 以检查命令”。这背后有一个问题:该机器人在 5 秒内向不同的所有者发送了大约 30 条消息,而我的机器人最终因垃圾邮件的不和谐原因而被禁止。经过几次尝试后,我了解到可以每 15 秒发送一次 dm,以免被禁止。
我如何为每个dm添加冷却时间?例如,如果有人添加它,机器人会向所有者发送一个 dm,然后另一个所有者在 15 秒之前邀请该机器人,但他会在冷却后收到 dm。我使用的命令:
@bot.event
async def on_guild_join(guild):
await guild.owner.send("Thanks for inviting the bot! Type -help to check the commands!")
解决方案
简单的。您可以asyncio.sleep
用于等待
import asyncio
@bot.event
async def on_guild_join(guild):
await asyncio.sleep(time_seconds)
await guild.owner.send("Thanks for inviting the bot! Type -help to check the commands!")
推荐阅读
- excel - 如何在Excel中的n个单元格中保持恒定的值并在结束后通过添加固定数字来更改它
- google-analytics - 将用户 ID 从 Google Tag Manager 发送到 Google Analytics 4
- c - 在 fclose 函数中,哪一个加了锁逻辑代码?
- f# - 如何使用任意数量的参数来约束函数的返回类型?
- javascript - 如何在 JavaScript 代码中查找多个 div ID
- c++ - 调用 va_start 是否需要具有可变参数的函数?
- excel - Excel 错误地将数值从英语翻译为荷兰语
- python - 对列表中的元素进行分组以创建基于数字作为键的字典
- r - 当 JSON 作为变量存储在 R Dataframe 中时解码 JSON
- windows - 无法使用 MinGW32 gcc / ld 将 64 位目标文件链接到可执行文件