How do I use discord.py in a non-interactive way (without loop)? #6278
-
Hi, my intention is to make a simple, one-time script, which connects to my discord server, downloads information about my members, and finishes. That's it, no loop, no interactivity. Only I decide when I manually run it. I couldn't find any example for that. Even the background task example hangs in the loop. I'm new to all the async/await stuff in Python, so perhaps the answer isn't specific to discord.py, but nevertheless so far I'm lost. Could someone give me some guidance? Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
Run your code and log off within e.g. class Client(discord.Client):
async def on_ready(self):
# my code here...
await self.close()
client = Client()
client.run('token') I would have recommended webhooks which are more lightweight if your use case was just sending messages but it seems you want to do more and it seems to involve the gateway machinery as well so this is probably the easiest thing to do what you want. |
Beta Was this translation helpful? Give feedback.
Run your code and log off within
on_ready
.e.g.
I would have recommended webhooks which are more lightweight if your use case was just sending messages but it seems you want to do more and it seems to involve the gateway machinery as well so this is probably the easiest thing to do what you want.