#Imports and Bot Command definition import discord from discord.ext import commands import random import asyncio bot = commands.Bot(command_prefix="~") #Bot Function: Initial Login client = discord.Client() @client.event async def on_ready(): print('Logged in as') print(client.user.name) print(client.user.id) print('------') @client.event async def on_message(message): if message.content.startswith('~test'): counter = 0 tmp = await client.send_message(message.channel, 'Calculating messages...') async for log in client.logs_from(message.channel, limit=100): if log.author == message.author: counter += 1 await client.edit_message(tmp, 'You have {} messages.'.format(counter)) elif message.content.startswith('!sleep'): await asyncio.sleep(5) await client.send_message(message.channel, 'Done sleeping') client.run('token') #Bot Function: Hello @client.event async def on_message(message): if message.author==client.user: #Returns nothing if the bot is the one to mention itself. return() if((message.author != client.user) and (message.content.startswith("~hello"))): #Returns "Hello, !" if the mention does not come from the bot. msg = "Hello, {0.author.mention}!".format(message) await client.send_message(message.channel, msg) #Bot Function: Random Operator- Attack @bot.command() async def on_message(message): if message.content.startswith("~rop atk"): infile=open("attackers.txt", "r") count = random.randint(0, 83) c = 0 line = infile.readline() while c != count: c = c + 1 line = infile.readline() if c == count: operator = line msg = "{0.author.mention}, you will be playing "+operator.format(message) await client.send_message(message.channel, msg)