Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Trying to make a remind command with discord.py

I have been trying to create a remind command in Discord.py, and I have it nearly finished, I am just running into an issue with the task that searches the reminder database (MongoDB), and retrieves reminders that are expiring to DM the author. Here is my full code for this command and task:

class remind(commands.Cog):
    def __init__(self, bot):
        self.bot = bot
        self.reminder_task.start()

    def cog_unload(self):
        self.reminder_task.cancel()

    @tasks.loop(minutes=1.0)
    async def reminder_task(self):
        data = collection.find({}).to_list(length=None)
        # async for i in data:
        for reminder in data:
            now = datetime.now()
            remindme = str({reminder['time']})
            remind = datetime.strptime(remindme, "%Y-%m-%d %H:%M:%S.%f")
            if now >= remind:
                guild = self.client.get_guild(remind['GuildID'])
                member = guild.get_member(remind['author_id'])
                await member.send(f"Reminder: `{remind['msg']}`")



    @slash_commands.command(name="remind", description="create a reminder!", options=[Option("time", "time until I remind you", Type.STRING, required=True), Option("reminder", "what should I remind you about?", Type.STRING, required=True)], guild_ids=bonbot_support)
    async def remind(self, ctx, time, reminder):
        time_conversion = {"s": 1, "m": 60, "h": 3600, "d": 86400, "w": 604800}
        remindseconds = int(time[0]) * time_conversion[time[-1]]
        remindertime = datetime.now() + timedelta(seconds=remindseconds)
        author_id = ctx.author.id
        guild_id = ctx.guild.id
        if ctx.author.bot:
                return

        rem_info = {"author_id": author_id, "GuildID": guild_id, "time": remindertime, "msg": reminder}

        await collection.insert_one(rem_info)
        await ctx.send('Reminder was set!')


def setup(bot):
    bot.add_cog(remind(bot))

The error I can’t get rid of is as follows:

    remindme = str({reminder['time']})
TypeError: '_asyncio.Future' object is not subscriptable

anyone have any ideas?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Replace data = collection.find({}).to_list(length=None) with data = await collection.find({}).to_list(length=None) because you try to use future object.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading