forked from elliotnash/DiscordChannelLink
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
56 lines (45 loc) · 1.37 KB
/
bot.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import discord
import toml
config = toml.load('config.toml')
TOKEN = config['TOKEN']
CHANNELS_TO_SYNC = config['SYNCED_CHANNELS']
client = discord.Client()
async def get_webhook(channel):
webhooks = await channel.webhooks()
for webhook in webhooks:
if webhook.token != "":
return webhook
return await channel.create_webhook(name="SyncHook")
@client.event
async def on_ready():
print(f'Client connected as {client.user}')
@client.event
async def on_message(msg):
if msg.channel.id in CHANNELS_TO_SYNC and not msg.webhook_id:
for channel_id in CHANNELS_TO_SYNC:
if channel_id == msg.channel.id:
continue
channel = await client.fetch_channel(channel_id)
webhook = await get_webhook(channel)
username = msg.author.name
avatar_url = msg.author.avatar_url
content = msg.content
embeds = msg.embeds
files = []
for attachment in msg.attachments:
await webhook.send(
content=attachment.url,
username=username,
avatar_url=avatar_url,
allowed_mentions=discord.AllowedMentions.none()
)
if content or embeds:
await webhook.send(
content=content,
username=username,
avatar_url=avatar_url,
files=files,
embeds=embeds,
allowed_mentions=discord.AllowedMentions.none()
)
client.run(TOKEN)