Advertisement
Guest User

bot

a guest
May 24th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.22 KB | None | 0 0
  1. import discord
  2. import random
  3. from discord.ext import commands
  4. from discord.ext.commands import Bot
  5. import asyncio
  6. import json
  7. import os
  8.  
  9. # the prefix that will trigger commands
  10. bot = commands.Bot(command_prefix='.')
  11. TOKEN = 'hidden sry'
  12. d = {"warning1": []}
  13.  
  14.  
  15. @bot.event
  16. async def on_ready():
  17.     print("Ready when you are")
  18.     print(f"I am running on: {bot.user.name}")
  19.     print(f"With the ID: {bot.user.id}")
  20.     print(discord.__version__)
  21.  
  22.  
  23. @bot.command()
  24. async def userinfo(ctx, user: discord.Member=None): # user: discord.User takes on the person tagged
  25.         alltheroles = ""
  26.     #    if ctx.channel.id == 445924221021978624:  # check if it's in the right channel
  27.     #       await ctx.author.send("test") # for private message
  28.         embed = discord.Embed(title="User info for " + str(user), description="Below you'll find your user info!", color=0xeee657)
  29.         embed.add_field(name="Nickname", value=str(user), inline=False)
  30.         embed.add_field(name="User ID", value=user.id, inline=False)
  31.         for i in range(0, len(user.roles)):
  32.             alltheroles += str(user.roles[i])
  33.             alltheroles += ", "
  34.         embed.add_field(name="Roles", value=alltheroles, inline=False)
  35.         await ctx.send(embed=embed)
  36.  
  37.  
  38. @bot.command()
  39. async def warn(ctx, user: discord.Member=None):
  40.     with open("test.json", "r") as fp:
  41.         d["warning1"].append(str(user.id))
  42.         await ctx.send(d["warning1"])
  43.  
  44.  
  45. @bot.command()
  46. async def choose(ctx, *args):
  47.     choices = [*args]
  48.     await ctx.send(random.choice(choices))
  49.  
  50.  
  51. @bot.event
  52. async def on_message(message):
  53.     if message.channel.id == 445924221021978624 and message.author.id != 444166970380648448:
  54.         await message.channel.send("<@227896738873212929> {0} has requested your assistance!".format(message.author))
  55.     pass
  56.  
  57.     await bot.process_commands(message)
  58.  
  59.  
  60. @bot.after_invoke
  61. async def after_any_command(ctx):  # if any command is called
  62.     channel = bot.get_channel(445928176624074752)
  63.     await channel.send("User {0} has used command: ".format(ctx.author) + "{0.command}".format(ctx))
  64.     # {0} to pass the name and {0.command} to pass the command used (ctx is the context that triggered  command
  65.     pass
  66.  
  67.  
  68. bot.run(TOKEN)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement