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)
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
@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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.