discord.py 在特定时间发送频道消息 [英] discord.py send channel message at specific time
本文介绍了discord.py 在特定时间发送频道消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望我的不和谐 python 机器人每天 2 次在频道中发送特定消息.首先是欧洲/柏林时间的 12 点,然后是 18 点(或仅从服务器时间开始).
I want my discord python bot to send a specific message in a channel 2 times a day. First at 12 o'clock and then 18 o'clock in Europe/Berlin time (or just from the server time).
我是怎么做到的?我尝试了很多东西,但我找不到方法.
How do I make it? I tried many things but I can't find a way to do it.
推荐答案
您可以使用 APScheduler
和 Cron
来安排您的消息在特定时间发送,例如中午 12:00
You can use APScheduler
and Cron
to schedule your messages to be sent at a specific time, like 12:00 AM
文档:APScheduler
, Cron
这是一个例子:
#async scheduler so it does not block other events
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from apscheduler.triggers.cron import CronTrigger
from discord.ext import commands
import discord
bot = commands.Bot(command_prefix="!")
async def func():
await bot.wait_until_ready()
c = bot.get_channel(channel_id)
await c.send("Your Message")
@bot.event
async def on_ready():
print("Ready")
#initializing scheduler
scheduler = AsyncIOScheduler()
#sends "Your Message" at 12PM and 18PM (Local Time)
scheduler.add_job(func, CronTrigger(hour="12, 18", minute="0", second="0"))
#starting the scheduler
scheduler.start()
这篇关于discord.py 在特定时间发送频道消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文