discord-keyword-bot/bot.py

26 lines
944 B
Python
Raw Normal View History

2020-03-21 01:11:44 +00:00
import discord
import os
import re
from dotenv import load_dotenv
# https://discordpy.readthedocs.io/en/latest/api.html
class MyClient(discord.Client):
async def on_ready(self):
print('Logged on as', self.user)
async def on_message(self, message):
2020-03-21 01:19:53 +00:00
if message.channel.id == int(os.getenv("SOURCE_CHANNEL")):
2020-03-21 01:11:44 +00:00
if re.match(os.getenv("REGEX_MATCH"), message.content, re.IGNORECASE):
2020-03-21 01:19:53 +00:00
chan_list = [x.strip() for x in os.getenv("DISCORD_CHANNELS").split(',')]
for channel_id in chan_list:
channel = client.get_channel(int(channel_id))
2020-03-21 02:00:53 +00:00
ping_string = ''
if os.getenv("PING_ROLE") != '':
ping_string = '<@&' + os.getenv("PING_ROLE") + '>: '
await channel.send(ping_string + message.content)
2020-03-21 01:11:44 +00:00
load_dotenv()
client = MyClient()
client.run(os.getenv("DISCORD_TOKEN"), bot=False)