Browse Source

Re-add multi-channel support

master
Daniel Mason 1 year ago
parent
commit
1144a4cb2f
  1. 2
      .env.example
  2. 2
      README.md
  3. 6
      bot.py

2
.env.example

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

2
README.md

@ -17,7 +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"
DISCORD_CHANNELS="channel_1_id,channel_2_id"
SOURCE_CHANNEL="channel_id_to_listen_to"
REGEX_MATCH="^.*(REGEX|TO|USE|TO|MATCH).*$"

6
bot.py

@ -12,8 +12,10 @@ 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):
channel = client.get_channel(int(os.getenv("DISCORD_CHANNEL")))
await channel.send(message.content)
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))
await channel.send(message.content)
load_dotenv()
client = MyClient()

Loading…
Cancel
Save