Yoshi_E

simple python discord bot - starting binary

Jul 22nd, 2019
130
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import asyncio
  2. import discord
  3. import os
  4. from discord.ext import commands
  5. from discord.ext import commands
  6. from discord.ext.commands import has_permissions, CheckFailure
  7. import shlex, subprocess
  8.  
  9. bot = commands.Bot(command_prefix="!", pm_help=True)
  10.  
  11. class ServerCommands(commands.Cog):
  12.     @commands.command(name='start',
  13.             brief="Starts the arma server",
  14.             pass_context=True)
  15.     @has_permissions(administrator=True)
  16.     async def start(self, ctx):
  17.         await ctx.send("Starting Server...")  
  18.         subprocess.call(shlex.split('"D:\Server\Program Files (x86)\arma3server_x64.exe" -port=2302 "-config=D:\Server\arma3\TADST\default\TADST_config.cfg" "-cfg=D:\Server\arma3\TADST\default\TADST_basic.cfg" "-profiles=D:\Server\arma3\TADST\default" -name=default -filePatching'))  
  19.    
  20.     @commands.command(name='stop',
  21.             brief="Stop the arma server",
  22.             pass_context=True)
  23.     @has_permissions(administrator=True)
  24.     async def stop(self, ctx):
  25.         os.system('taskkill /f /im "arma3server_x64.exe"')
  26.         await ctx.send("Stop the Server.")  
  27.  
  28. @bot.event
  29. async def on_ready():
  30.  
  31.     print('Logged in as')
  32.     print(bot.user.name)
  33.     print(bot.user.id)
  34.     print('------------')
  35.  
  36. def main():
  37.     bot.add_cog(ServerCommands(bot))  
  38.     bot.run("ENTER_TOKEN")
  39.  
  40. if __name__ == '__main__':
  41.     main()
  42.  
  43.  
  44.            
  45. #make bot join server:
  46. # https://discordapp.com/oauth2/authorize?client_id=xxxxxx&scope=bot
  47.  
  48. #https://discordpy.readthedocs.io/en/rewrite/ext/commands/api.html#event-reference
RAW Paste Data