viewing paste Unknown #43517 | Text

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
#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, <user>!" 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)
            
 
Viewed 914 times, submitted by Guest.