This commit is contained in:
Daniel Mason 2020-03-21 15:42:08 +13:00
parent b5624db074
commit 2fd99c369c
3 changed files with 4 additions and 11 deletions

View File

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

View File

@ -17,8 +17,7 @@ copy .env.example to .env and setup your user Token in .env
.env file layout
DISCORD_TOKEN="token_from_web"
DISCORD_CHANNELS="channel_1_id,channel_2_id"
DISCORD_CHANNELS="channel_1_id"
SOURCE_CHANNEL="channel_id_to_listen_to"
REGEX_MATCH="^.*(REGEX|TO|USE|TO|MATCH).*$"
PING_ROLE="id_of_role"

9
bot.py
View File

@ -12,13 +12,8 @@ class MyClient(discord.Client):
async def on_message(self, message):
if message.channel.id == int(os.getenv("SOURCE_CHANNEL")):
if re.match(os.getenv("REGEX_MATCH"), message.content, re.IGNORECASE):
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))
ping_string = ''
if os.getenv("PING_ROLE") != '':
ping_string = '<@&' + os.getenv("PING_ROLE") + '>: '
await channel.send(ping_string + message.content)
channel = client.get_channel(int(os.getenv("DISCORD_CHANNEL"))
await channel.send(message.content)
load_dotenv()
client = MyClient()