-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
33 lines (25 loc) · 1023 Bytes
/
app.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
#! /usr/bin/env python3
import discord
import yaml
import aiohttp
config = yaml.safe_load(open('./config.yaml'))
channel_ids = [ids.get('id') for ids in config['channels']]
channel_webhooks = [ids.get('webhook') for ids in config['channels']]
intents = discord.Intents(messages=True, message_content=True)
client = discord.Client(intents=intents)
@client.event
async def on_ready():
print('bot is ready.')
@client.event
async def on_message(message):
if message.author.bot:
return
if message.channel.id in channel_ids:
msg_guild_index = channel_ids.index(message.channel.id)
webhooks = [i for i in channel_webhooks]
del webhooks[msg_guild_index]
for url in webhooks:
async with aiohttp.ClientSession() as session:
webhook = discord.Webhook.from_url(url, session=session)
await webhook.send(message.content, username=message.author.name, avatar_url=message.author.display_avatar.url)
client.run(config['discord_token'])