Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- try:
- import discord
- except ImportError:
- import pip
- pip.main(['install', 'discord'])
- import discord
- try:
- with open('config.json') as f:
- config = json.load(f)
- except FileNotFoundError:
- with open('config.json', 'w') as f:
- config = {}
- print("config file created.")
- json.dump({'discord_token': '', 'response': '', 'words': ['']}, f)
- desc = """
- Simple moderation bot.
- """
- client = discord.Client(description=desc)
- @client.event
- async def on_message(message: discord.Message):
- if message.author.bot:
- return
- if any([word in message.content for word in config['words']]):
- await client.send_message(message.channel, '{}: {}'.format(message.author.mention, config['response']))
- @client.event
- async def on_ready():
- app_info = await client.application_info()
- client.owner = app_info.owner
- print('Bot: {0.name}:{0.id}'.format(client.user))
- print('Owner: {0.name}:{0.id}'.format(client.owner))
- print('------------------')
- perms = discord.Permissions.none()
- perms.administrator = True
- url = discord.utils.oauth_url(app_info.id, perms)
- print('To invite me to a server, use this link\n{}'.format(url))
- if __name__ == '__main__':
- try:
- client.run(config['discord_token'])
- except KeyError:
- print("config not yet filled out.")
- except discord.errors.LoginFailure as e:
- print("Invalid discord token.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement