Advertisement
Starbounce

Discord Bot Template

Nov 9th, 2019
563
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. import discord
  2. from discord.ext import commands
  3. import asyncio
  4. import random
  5. import time
  6.  
  7. Client = discord.Client()
  8. client = commands.Bot(command_prefix = '!')
  9. client.remove_command('help')
  10.  
  11. IGNORED = (commands.CommandOnCooldown, commands.CommandNotFound)
  12. TOKEN = ""
  13. OWNER = ""
  14. COOLDOWN = 3
  15.  
  16. #https://discordapp.com/oauth2/authorize?&client_id=YOURCLIENTHERE&scope=bot&permissions=YOURPERMSHERE
  17.  
  18.  
  19. @client.event
  20. async def on_ready():
  21. print("Bot is online")
  22. await client.change_presence(game=discord.Game(name=''))
  23.  
  24. @client.event
  25. async def on_resumed():
  26. print("Bot has reconnected")
  27.  
  28.  
  29. @client.event
  30. async def on_command_error(err, ctx):
  31. if isinstance(err, IGNORED):
  32. return
  33. elif isinstance(err, TypeError):
  34. await client.send_message(ctx.message.channel, "What? I don't understand how to do this")
  35. else:
  36. await client.send_message(ctx.message.channel, "Uhmmmm, something went wrong there...")
  37. print("Command: " + ctx.message.content + "\nError: ")
  38. print(err)
  39.  
  40.  
  41. ##########################################################
  42.  
  43. @client.event
  44. async def on_message(message):
  45. if message.content.lower == "horse":
  46. await client.send_message(message.channel, "pussy")
  47.  
  48.  
  49. await client.process_commands(message)
  50.  
  51. @client.command()
  52. @commands.cooldown(1, COOLDOWN, commands.BucketType.user)
  53. async def bon():
  54. await client.say("bon")
  55.  
  56. @client.command(pass_context=True)
  57. async def rest(ctx):
  58. if ctx.message.author.id == OWNER:
  59. await client.say("Goodnight!")
  60. id = ctx.message.server.id
  61. await client.close()
  62. print('Bot is offline')
  63. else:
  64. await client.say("You're not the boss of me!")
  65.  
  66.  
  67. ##########################################################
  68.  
  69.  
  70.  
  71. def run_client(client, *args, **kwargs):
  72. loop = asyncio.get_event_loop()
  73. while True:
  74. try:
  75. loop.run_until_complete(client.start(*args, **kwargs))
  76. except Exception as e:
  77. print("Error", e)
  78. print("Waiting until restart")
  79. time.sleep(600)
  80.  
  81. if __name__ == "__main__":
  82. run_client(client, TOKEN)
  83.  
  84. input("Bot ended")
  85.  
  86. quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement