I have this code where I modify the global variable afk_list which is a dictionary:
afk_list = {}
@client.application_command(name="afk-for", guilds=[731083709658169344])
async def afk_for(ctx: ApplicationContext, time: Option(int, name="time", min_value=1, max_value=60), unit: Option(str, choices=["seconds", "minuts", "hours"])):
if ctx.author.voice is None:
await ctx.respond("You must be in a voice channel!", ephemeral=True)
return
units = {
"secondes": "sec",
"minutes": "min",
"heures": "h"
}
last_nick = ctx.author.nick or ctx.author.name
new_nick = f"[AFK {time}{units[unit]}] {last_nick}"
global afk_list # Issue is here
afk_list[ctx.author.id] = last_nick # And here
await ctx.author.edit(nick=new_nick)
await ctx.respond("You are now AFK", ephemeral=True)
However when I access the variable afk_list in a voice_state_event, the key has not been created and the dictionary is still empty.
Is it due to the fact that it is an asynchronous function?