Advertisement
Guest User

Bopy

a guest
Jun 26th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. import json
  2. try:
  3. import discord
  4. except ImportError:
  5. import pip
  6. pip.main(['install', 'discord'])
  7. import discord
  8.  
  9. try:
  10. with open('config.json') as f:
  11. config = json.load(f)
  12. except FileNotFoundError:
  13. with open('config.json', 'w') as f:
  14. config = {}
  15. print("config file created.")
  16. json.dump({'discord_token': '', 'response': '', 'words': ['']}, f)
  17.  
  18.  
  19. desc = """
  20. Simple moderation bot.
  21. """
  22. client = discord.Client(description=desc)
  23.  
  24.  
  25. @client.event
  26. async def on_message(message: discord.Message):
  27. if message.author.bot:
  28. return
  29. if any([word in message.content for word in config['words']]):
  30. await client.send_message(message.channel, '{}: {}'.format(message.author.mention, config['response']))
  31.  
  32.  
  33. @client.event
  34. async def on_ready():
  35. app_info = await client.application_info()
  36. client.owner = app_info.owner
  37. print('Bot: {0.name}:{0.id}'.format(client.user))
  38. print('Owner: {0.name}:{0.id}'.format(client.owner))
  39. print('------------------')
  40. perms = discord.Permissions.none()
  41. perms.administrator = True
  42. url = discord.utils.oauth_url(app_info.id, perms)
  43. print('To invite me to a server, use this link\n{}'.format(url))
  44.  
  45.  
  46. if __name__ == '__main__':
  47. try:
  48. client.run(config['discord_token'])
  49. except KeyError:
  50. print("config not yet filled out.")
  51. except discord.errors.LoginFailure as e:
  52. print("Invalid discord token.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement