0

I'm making a discord bot which you can interact with by adding reactions, and i want to add quite a bit of options options. Awaiting the add_reaction call takes too long for my use case, and i want to do it asynchronously. How would i go about this?

Code:

import discord

token = "#####"

client = discord.Client()

voting_options = ["\U0001F1E6", "\U0001F1E7", "\U0001F1E8", "\U0001F1E9", "\U0001F1EA"]

@client.event
async def on_message(ctx):
    if ctx.content == ".poll":
        message = await client.send_message(ctx.channel, "Vote now!")
        for option in voting_options:
            await client.add_reaction(message, option)

client.run(token)

Result: https://gyazo.com/ae31b98bed42ef2358f2227026df4263

How would i go about making this threaded?

1 Answer 1

1

You can use

 asyncio.create_task(client.add_reaction(message, option))

to create a task. However, that is not threaded, but asynchronously (thats how asyncio works), but I think that's what you're looking for.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I had to update to python 3.7 but it worked nicely once i did!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.