有没有办法把消息发送到公会的系统频道,并在定时任务中使用?

Is there a way to send messages to a guild's system channel, and use it in a scheduled task?

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 属性。我假设你自己设置公会。