Skip to content Skip to sidebar Skip to footer

Making A Bot That Sends Messages At A Scheduled Date With Discord.py

I'm trying to make a bot that sends a scheduled message to a specific text channel. for example at the date of my birthday saying 'happy birthday', or also every morning saying 'Go

Solution 1:

Here's how you would do something like this using the tasks extension

from discord.ext import commands, tasks

bot = commands.Bot("!")

target_channel_id = 1234@tasks.loop(hours=24)asyncdefcalled_once_a_day():
    message_channel = bot.get_channel(target_channel_id)
    print(f"Got channel {message_channel}")
    await message_channel.send("Your message")

@called_once_a_day.before_loopasyncdefbefore():
    await bot.wait_until_ready()
    print("Finished waiting")

called_once_a_day.start()
bot.run("token")

Solution 2:

You can also try to use aiocron.

pip install aiocron

https://github.com/gawel/aiocron

Add below to your bot code before the bot.run(TOKEN)

import aiocron

CHANNEL_ID=1234@aiocron.crontab('0 * * * *')asyncdefcornjob1():
    channel = bot.get_channel(CHANNEL_ID)
    await channel.send('Hour Cron Test')

Post a Comment for "Making A Bot That Sends Messages At A Scheduled Date With Discord.py"