mephasor / mephaBot

Little Discord Bot that I use to play radio streams and other random stuff.
GNU General Public License v3.0
3 stars 3 forks source link

Run bot with token rather than login creds #1

Closed Chiharuuu closed 8 years ago

Chiharuuu commented 8 years ago

Is it possible to make this bot run as a proper account with bot token? I've tried converting it with what limited knowledge of python that I have, and it's just not working for whatever reason.

configReader.py Edits ``` import re p = re.compile(r"DiscordName=(.*)\nDiscordPW=(.*)\nDiscordToken=(.*)\n.*\n.*\nOwnerID=(.*)") q = re.compile(r"ADDON=(.*)\n") configPath = 'cfg/botConfig.cfg' class ConfigReader: username = '' password = '' token = '' ownerID = '' addonList = [] def readConfig(self): cfgFile = open(configPath, 'r') cfgContent = cfgFile.read() result = re.search(p, cfgContent) self.username = result.groups()[0] self.password = result.groups()[1] self.token = result.groups()[2] self.ownerID = result.groups()[3] addonResults = re.findall(q, cfgContent) for addon in addonResults: print('cfgAddonFound: '+addon) self.addonList.append(addon) def getUsername(self): return self.username def getPW(self): return self.password def getToken(self): return self.token def getOwnerID(self): return self.ownerID def getAddonList(self): return self.addonList ```
runBot.py Edits ``` def runBot(self): #super().run(self.cfg.getUsername(), self.cfg.getPW()) super().run(self.cfg.getToken()) ```
botConfig.cfg Edits ``` ## DiscordCredentials DiscordName=email (redacted) DiscordPW=password (redacted) DiscordToken=token (redacted) #Owner Settings OwnerID=id (redacted) DefaultVoiceChannel=channel (redacted) #Addon list goes here ADDON=onlineRadio ```

I've tried everything that I can think of, and every time I run the bot it throws back this:

cfgAddonFound: onlineRadio
Traceback (most recent call last):
  File "runBot.py", line 101, in <module>
    main()
  File "runBot.py", line 98, in main
    myBot.runBot()
  File "runBot.py", line 30, in runBot
    super().run(self.cfg.getToken())
  File "/usr/local/lib/python3.5/dist-packages/discord/client.py", line 467, in run
    self.loop.run_until_complete(self.start(*args))
  File "/usr/lib/python3.5/asyncio/base_events.py", line 337, in run_until_complete
    return future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 274, in result
    raise self._exception
  File "/usr/lib/python3.5/asyncio/tasks.py", line 239, in _step
    result = coro.send(None)
  File "/usr/local/lib/python3.5/dist-packages/discord/client.py", line 438, in start
    yield from self.login(*args)
  File "/usr/local/lib/python3.5/dist-packages/discord/client.py", line 368, in login
    yield from getattr(self, '_login_' + str(n))(*args)
  File "/usr/local/lib/python3.5/dist-packages/discord/client.py", line 292, in _login_1
    raise LoginFailure('Improper token has been passed.')
discord.errors.LoginFailure: Improper token has been passed.
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7f837b8ef860>

Maybe I'm just stupid and know nothing about Python/discord.py, but I'd appreciate any help on this... been trying for a while now and just can't get it to work properly.

mephasor commented 8 years ago

Yup, it is possible and should not be difficult to achieve, I will look into it. :)

mephasor commented 8 years ago

Check out the latest commit. Please dont forget to update to the current discord.py library:

python3.5 -m pip install --upgrade discord.py