I am using discord.py async version and I need to assign a role 10.5 minutes after a user joins a server. I was considering using threading.Timer(..) but member.add_roles(...) is a coroutine and therefore Timer will not await it.
I tried an alternate method using loop.call_later(...) but in my testing I get a RuntimeWarning that my coroutine to add roles, add_roles, was never waiting. Here's what I tried so far:
import discord, asyncio
from discord.utils import get
client = discord.Client()
async def on_member_join(member):
...
newuser, noparty = get(member.guild.roles, name="New Member"), get(member.guild.roles, name="No Party")
async def add_roles(member, newuser, noparty):
await member.add_roles(newuser, noparty, reason="Auto-role new users.")
loop = asyncio.get_event_loop()
loop.call_later(630, add_roles, member, newuser, noparty)
The expected outcome is that after 10.5 minutes the member will be assigned the New User and No Party roles, but instead I get the RuntimeWarning described above. My questions are: is this the proper approach? Or can I simply use asyncio.sleep(630) since the rest of my program is async functions? Any help is appreciated.