如何解决有没有办法将消息发送到公会的系统通道,并在计划任务中使用它?
async def rules_reminder(self):
channel = self.bot.guild.system_channel
await channel.send("Remember to adhere to the rules!")
self.scheduler.add_job(self.rules_reminder,CronTrigger(second="0,15,30,45"))
解决方法
您可以为此使用 discord.ext.tasks。 discord.ext.tasks 是一个 discord.py 扩展,允许用户轻松创建重复任务。对于您的代码,这将是 discord.ext.tasks 版本:
from discord.ext import tasks # Somewhere...
# --------------------------------------------
# Preferably somewhere in your cog's __init__...
self.rules_reminder.start()
@tasks.loop(seconds=15)
async def rules_reminder(self):
channel = self.bot.guild.system_channel
await channel.send("Remember to adhere to the rules!")
最后一件事,只是为了确保您知道:commands.Bot 或 discord.Client 都没有 guild
属性。我假设你自己设置了公会。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。