From c4437c645273e3c4467c9f65277bcd2f0c77c666 Mon Sep 17 00:00:00 2001 From: Sami <saku537@gmail.com> Date: Tue, 24 Jul 2018 22:15:18 +0300 Subject: [PATCH] Added a new bot, to the async branch. --- AsmOrg-bot/bot.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 AsmOrg-bot/bot.py diff --git a/AsmOrg-bot/bot.py b/AsmOrg-bot/bot.py new file mode 100644 index 0000000..bfcb11e --- /dev/null +++ b/AsmOrg-bot/bot.py @@ -0,0 +1,38 @@ +# Author: samip5 + +import discord +from discord.ext import commands +import datetime + + +def get_prefix(bot, message): + prefixes = ['!!'] + return commands.when_mentioned_or(*prefixes)(bot, message) + + +bot = commands.Bot(command_prefix=get_prefix) + + +@bot.event +async def on_ready(): + bot.uptime = datetime.datetime.utcnow() + print('Logged in as:\n{0} (ID: {0.id})'.format(bot.user)) + bot.accept_invite('https://discord.gg/mPUDfwa') + print(f'Servers count: {len(bot.servers)}') + + +@bot.event +async def on_message(message): + if message.channel.is_private and message.content.startswith('http') or message.channel.is_private and message.content.startswith('https'): + try: + invite = await bot.get_invite(message.content) + await bot.accept_invite(invite) + await bot.send_message(message.channel, 'Joined the server.') + except: + # if an error occurs at this point then ignore it and move on. + pass + finally: + return + await bot.process_commands(message) + +bot.run() \ No newline at end of file -- GitLab