Forums

Troubles running a Discord bot

I'm trying to run a Discord bot I made using version 3.6, but whenever I run it here it runs on 3.7, and then afterwards it gives me this error:

Traceback (most recent call last):
 File "/home/JustSomeBotDev/RK800 Bot.py", line 1, in <module>
   import discord
ModuleNotFoundError: No module named 'discord'

Is there a way to:

A) Make it run on 3.6

B) Import discord.py successfully?

[I apologise if this problem has already been covered.]

To run something using Python 3.6, just use the appropriate Python interpreter from a Bash console -- for example, to run a file called "RK800 Bot.py", start a bash console and run

python3.6 'RK800 Bot.py'

(The quotes are necessary because there is a space in the filename.)

You might also need to install the discord module, as we don't have it installed by default:

pip3.6 install --user discord

However, all that said, it might not work even then -- free accounts on PythonAnywhere need to access the public Internet through a proxy, and I don't think the discord package is currently able to do that :-( It would work from a paid account, though.

Your suggestion did work, however I have encountered another error:

 Traceback (most recent call last):
  File "RK800 Bot.py", line 444, in <module>
    client.run("[token censored out]")
File "/home/JustSomeBotDev/.local/lib/python3.6/site-packages/discord/client.py", line 519, in run
    self.loop.run_until_complete(self.start(*args, **kwargs))
File "/usr/lib/python3.6/asyncio/base_events.py", line 468, in run_until_complete
   return future.result()
File "/home/JustSomeBotDev/.local/lib/python3.6/site-packages/discord/client.py", line 490, in start
  yield from self.login(*args, **kwargs)
File "/home/JustSomeBotDev/.local/lib/python3.6/site-packages/discord/client.py", line 416, in login
  yield from getattr(self, '_login_' + str(n))(*args, **kwargs)
File "/home/JustSomeBotDev/.local/lib/python3.6/site-packages/discord/client.py", line 346, in _login_1
  data = yield from self.http.static_login(token, bot=is_bot)
File "/home/JustSomeBotDev/.local/lib/python3.6/site-packages/discord/http.py", line 258, in static_login
  data = yield from self.request(Route('GET', '/users/@me'))
File "/home/JustSomeBotDev/.local/lib/python3.6/site-packages/discord/http.py", line 137, in request
  r = yield from self.session.request(method, url, **kwargs)
File "/home/JustSomeBotDev/.local/lib/python3.6/site-packages/aiohttp/client.py", line 555, in __iter__
  resp = yield from self._coro
File "/home/JustSomeBotDev/.local/lib/python3.6/site-packages/aiohttp/client.py", line 198, in _request
      conn = yield from self._connector.connect(req)
File "/home/JustSomeBotDev/.local/lib/python3.6/site-packages/aiohttp/connector.py", line 314, in connect
.format(key, exc.strerror)) from exc
aiohttp.errors.ClientOSError: [Errno 111] Cannot connect to host discordapp.com:443 ssl:True [Can not connect 
to discordapp.com:443 [Conne
ct call failed ('104.16.58.5', 443)]]
 Unclosed client session
  client_session: <aiohttp.client.ClientSession object at 0x7f4b08fd23c8>
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7f4b08fd26a0>

Is this due to it needing to access a proxy, or what?

Yes, you'll need to configure the discord client to use the proxy. You'll have to check the docs to find out how to do that. The details for the proxy are here http://help.pythonanywhere.com/pages/403ForbiddenError/

how to setup proxy?

See the docs Glenn linked to above. Also, check the docs of the library you are using.

Hello! I'm trying to run a script with discord module and I got an error: " import discord ModuleNotFoundError: No module named 'discord'

ModuleNotFoundError: No module named 'discord'" The Python version is 3.10. Coul you help me solve this? Thanks.

Make sure that you have installed the module in the version of Python/virtualenv that you are using to run your code: https://help.pythonanywhere.com/pages/InstallingNewModules/