Browse Source

Initial Commit

master
Daniel Mason 1 year ago
commit
a480c2c898
  1. 4
      .env.example
  2. 1
      .gitignore
  3. 13
      README.md
  4. 21
      bot.py
  5. 2
      requirements.txt

4
.env.example

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

1
.gitignore

@ -0,0 +1 @@
.env

13
README.md

@ -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

@ -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

@ -0,0 +1,2 @@
python-dotenv
discord.py
Loading…
Cancel
Save