Implement welcome message on Discord

master
Nikola Forró 6 years ago
parent e27b138170
commit 2bdac9ab6e

@ -69,6 +69,7 @@ class DiscordClient(discord.Client):
self.logger.info('Logged in as {0}'.format(self.user.name))
async def on_message(self, message):
await self._process_new_member(message)
await self._process_announcement(message)
server = message.server.id if message.server else None
for pattern, action in self.supported_commands:
@ -79,9 +80,32 @@ class DiscordClient(discord.Client):
if cmd == message.content:
await self.send_message(message.channel, resp.format(user=message.author.mention))
async def _process_new_member(self, message):
new_members_channel = self.config['Discord'].get('new_members_channel')
info_channel = self.config['Discord'].get('info_channel')
welcome_channel = self.config['Discord'].get('welcome_channel')
welcome_pattern = self.config['Discord'].get('welcome_pattern')
if not message.channel or not message.server:
return
if message.channel.id != new_members_channel:
return
info_channel = [c for c in message.server.channels if c.id == info_channel]
if info_channel:
info_channel = info_channel[0]
else:
return
welcome_channel = discord.Object(welcome_channel)
try:
await self.send_message(welcome_channel, welcome_pattern.format(
user=message.author.mention, info_channel=info_channel.mention))
except discord.errors.Forbidden:
pass
async def _process_announcement(self, message):
announcer = self.config['Discord'].get('announcer')
channels = self.config['Discord'].get('announcement_channels').split(',')
if not message.author or not message.channel:
return
if message.author.id != announcer or message.channel.id not in channels:
return
after = datetime.datetime.utcnow() - datetime.timedelta(minutes=5)

@ -6,6 +6,13 @@ channels = lilialil
[Discord]
token = __DISCORD_TOKEN__
# #freshcheese
new_members_channel = 414316622208303104
# #♥-please_read-♥
info_channel = 439098968383946752
# #cheesewars
welcome_channel = 285154599038353408
welcome_pattern = Hi {user}! Welcome to the Cheese Horde! Please check out all of the various channels to the left for all your chatting needs and don't forget to read through {info_channel} as soon as you get the chance. :cheese:
# Bellateeny
announcer = 369539730989252609
# #cheesenouncements

Loading…
Cancel
Save