Skip to content

Create a periodic task for collecting messages from discord server. #6

@KDwevedi

Description

@KDwevedi

Description

The command add_messages collects messages from the C4GT Discord server and saves data in a database.
There is a need to have this task be automated so that it repeats at regular intervals (or at specific times) in the background while the bot is active

An illustration of a possible implementation for reference:

@tasks.loop(seconds=60)  # Runs every 60 seconds
async def my_task():
    guild_id = 1234567890  # Replace with the actual guild ID
    guild = bot.get_guild(guild_id)
    channel_id = 1234567890  # Replace with the actual channel ID
    channel = guild.get_channel(channel_id)

    start_command = bot.get_command('start_task')
    stop_command = bot.get_command('stop_task')

    ctx = await bot.get_context(channel)
    await start_command.invoke(ctx)

    await asyncio.sleep(10)  # Wait for 10 seconds

    await stop_command.invoke(ctx)

@bot.command()
async def start_task(ctx):
    my_task.start()
    await ctx.send('Task started!')

@bot.command()
async def stop_task(ctx):
    my_task.stop()
    await ctx.send('Task stopped!')

bot.run('YOUR_BOT_TOKEN')

Goals:

  • Create a Bot Task to implement above mentioned functionality.
  • Implement error handling so that the Bot notifies an assignable private channel meant for Bot error notifications.

Product Name:

C4GT

Project

Official Code4GovTech Discord Bot

Organization Name:

Samagra

Tech Skills Needed:

Python, Quart

Mentor(s)

@KDwevedi

Complexity

Low

Category

Feature

Sub Category

Refactoring, Beginner Friendly

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions