Reputation: 35
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?
Upvotes: 0
Views: 159
Reputation: 539
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.
Upvotes: 1