mirror of
https://github.com/skylanix/MamieHenriette.git
synced 2026-02-06 14:50:34 +01:00
discord bot dans l'interface web
This commit is contained in:
28
discordbot/__init__.py
Normal file
28
discordbot/__init__.py
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import random
|
||||||
|
import discord
|
||||||
|
import os
|
||||||
|
import logging
|
||||||
|
import asyncio
|
||||||
|
from database.models import Humeur
|
||||||
|
from webapp import webapp
|
||||||
|
|
||||||
|
class MyClient(discord.Client):
|
||||||
|
async def on_ready(self):
|
||||||
|
logging.info(f'Logged in as {self.user} (ID: {self.user.id})')
|
||||||
|
for c in self.get_all_channels() :
|
||||||
|
logging.info(f'{c.id} {c.name}')
|
||||||
|
self.loop.create_task(self.updateStatus())
|
||||||
|
# await self.get_channel(1123512494468644984).send("essai en python")
|
||||||
|
|
||||||
|
async def updateStatus(self):
|
||||||
|
humeur = random.choice(Humeur.query.all())
|
||||||
|
if humeur != None:
|
||||||
|
logging.info(f'changement de status {humeur.text}')
|
||||||
|
await self.change_presence(status = discord.Status.online, activity = discord.CustomActivity(humeur.text))
|
||||||
|
await asyncio.sleep(60)
|
||||||
|
|
||||||
|
intents = discord.Intents.default()
|
||||||
|
client = MyClient(intents=intents)
|
||||||
|
|
||||||
|
with webapp.app_context():
|
||||||
|
client.run(os.getenv('TOKEN'))
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
from webapp import webapp
|
from webapp import webapp
|
||||||
|
from discordbot import client
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
webapp.run(debug=True)
|
webapp.run(debug=True)
|
||||||
Reference in New Issue
Block a user