-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
34 lines (29 loc) · 1.09 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import asyncio
import os
import discord
from dotenv import load_dotenv # for env variables
import aiohttp # for webhook
# ENV
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
WEBHOOK = os.getenv('WEBHOOK')
# BOT
class Client(discord.Client):
async def on_message(self, message: discord.Message):
author : discord.Member = message.author
if author.bot or message.content == '':
return
if message.channel.name != 'lounge':
return
loop = asyncio.get_event_loop()
loop.create_task(message.delete())
#await message.delete()
async with aiohttp.ClientSession() as session:
webhook = discord.Webhook.from_url(WEBHOOK,
adapter=discord.AsyncWebhookAdapter(session))
await webhook.send(message.content, username=author.display_name,
avatar_url=author.avatar_url, allowed_mentions=discord.AllowedMentions(everyone=False))
async def on_ready(self):
print(f'{self.user} has connected to Discord!')
client = Client()
client.run(TOKEN)