import inspect import logging import os from discord.ext import commands import lib import heavynode DISCORD_TOKEN = os.environ['discord_token'] HEAVYNODE_TOKEN = os.environ['heavynode_token'] logging.basicConfig() bot = lib.MineBot(command_prefix='!') hn = heavynode.Client(HEAVYNODE_TOKEN) bot.add_cleanup(hn.shutdown) @bot.command() @commands.has_any_role('Admin', 'Mod') async def add(ctx, player): """Add a player to the server whitelist. Must use exact Minecraft name.""" await hn.send_command(f'whitelist add {player}') await ctx.send(f'"{player}" added to whitelist.') @bot.command() @commands.has_any_role('Admin', 'Mod') async def remove(ctx, player): """Remove a player from the server whitelist. Must use exact Minecraft name.""" await hn.send_command(f'whitelist remove {player}') await ctx.send(f'"{player}" removed from whitelist.') @add.error @remove.error async def whitelist_error(ctx, error): if isinstance(error, commands.CheckFailure): await ctx.send('You must be a server admin to use this command.') elif isinstance(error, heavynode.HttpError): await ctx.send('Failed to communicate with server.') else: raise error bot.run(DISCORD_TOKEN, reconnect=True)