Discord.py run Command every X times
Hey, I want to run the code from the c11 command every X minutes. It shouldn't require typing in the Command, it should run when the bot gets started. I don't know how to define ctx I hope someone understands what I mean.
@client.command()
async def c11(ctx):
await ctx.send("Erfolgreich level gestartet")
for _ in range(100):
time.sleep(5)
t = len(memberlist)
b = len(channellist)
countermem2 = 0
for _ in range(b):
countermem = 0
clist = int(channellist[(countermem2)])
for _ in range(t):
def _loadusers():
voice_channel = client.get_channel(clist)
members2 = voice_channel.members
voice_channel = client.get_channel(clist)
members2 = voice_channel.members
_loadusers()
id2 = memberlist[(countermem)]
id = int(memberlist[(countermem)])
member = ctx.guild.get_member(id) # You can use `ctx.author` if you want to check with the user that invoked the command
print (id)
_loadusers()
if member in voice_channel.members:
print(f"{member} is in the voice channel {voice_channel}")
print(voice_channel)
if id2 not in amounts:
print("was not in stats file")
amounts[id2] = 0
_save()
else:
print(f"{member} is not in the {voice_channel}")
amounts[id2] += 2
_save()
quotient = amounts[id2] / 200
if (quotient).is_integer():
channel = client.get_channel(802206147489562645)
await channel.send(f"<@{id}> hat Level {quotient} Erreicht WUHU!")
else:
print("it worked")
countermem += 1
countermem2 += 1
_save()
question from:https://stackoverflow.com/questions/66055402/discord-py-run-command-every-x-timescan I define or get ctx in a different way?