[英]Discord.py Sending an embed on the 15th every month
Right now I'm trying to make a @commands.Cog.listener()
or @client.event
which sends an embed every month (Like the 15th on every month)现在我正在尝试制作一个@commands.Cog.listener()
或@client.event
每个月发送一个嵌入(就像每个月的 15 号)
So far I just set up a task loop but I don't know how I could use datetime in the loop.到目前为止,我只是设置了一个任务循环,但我不知道如何在循环中使用日期时间。
from discord.ext import tasks, commands
import discord
class TasksCMD(commands.Cog):
def __init__(self, bot):
self.index = 0
self.bot = bot
self.printer.start()
#something here to wait for the 15th of every month and send one embed on that day
def setup(bot):
bot.add_cog(TasksCMD(bot))
Any tips would be greatly help!任何提示都会有很大帮助!
from datetime import datetime
@tasks.loop(hours=24)
async def check_time(ctx)
date = datetime.now()
if date.day == 15:
await ctx.send(embed=your_embed)
@bot.command()
async def start_loop(ctx):
check_time.start(ctx)
await ctx.send('Started loop')
if you want to start the loop on_ready
如果你想开始循环on_ready
@tasks.loop(hours=24)
async def check_time(channel)
date = datetime.now()
if date.day == 15:
await channel.send(embed=your_embed)
@bot.event
async def on_ready():
await bot.wait_until_ready()
print('Logged in as {0.user}'.format(bot))
channel = bot.get_channel(some_channel_id_here)
check_time.start(channel)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.