Initial Commit

This commit is contained in:
Daniel Mason 2020-03-21 14:11:44 +13:00
commit a480c2c898
5 changed files with 41 additions and 0 deletions

4
.env.example Normal file
View File

@ -0,0 +1,4 @@
DISCORD_TOKEN=""
DISCORD_CHANNELS="id1,id2,id3"
SOURCE_CHANNEL=""
REGEX_MATCH="^.*(K41|COVID).*$"

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.env

13
README.md Normal file
View File

@ -0,0 +1,13 @@
# Python Discord Keyword Bot
### Requirements
python3 / pip3
### Install
copy .env.example to .env and setup your user Token in .env
pip3 install -r requirements.txt
python3 boy.py

21
bot.py Normal file
View File

@ -0,0 +1,21 @@
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):
if message.channel.id == os.getenv("SOURCE_CHANNEL"):
if re.match(os.getenv("REGEX_MATCH"), message.content, re.IGNORECASE):
for channel_id in explode(os.getenv("DISCORD_CHANNELS")):
channel = client.get_channel(channel_id)
await channel.send('*' + message.content + '*')
load_dotenv()
client = MyClient()
client.run(os.getenv("DISCORD_TOKEN"), bot=False)

2
requirements.txt Normal file
View File

@ -0,0 +1,2 @@
python-dotenv
discord.py