Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Discord.py
-
@Webmaster4o Try it out,
It doesn't work for me, it says client not defined and I have no idea how to define it. -
@SpiesWithin This example is correct.
client
is defined withclient = discord.Client()
-
@Webmaster4o I'm telling you, just try it out I am getting error after error
-
I have always found the best way to get help is to describe exactly what error you get, and exactly what steps led you to that error. People might know the easy answer, and can give you the answer quickly by seeing the traceback, or an explanation of what you tried. I ignored this thread 5 or 6 times because I did not feel like figuring out where and how to install discord, or solving the other roadblock you implied that you encountered.. I guess seven times was the charm....
I installed discord.py using stash:
$ pip install discord.py
There were a few errors, because stash runs in py2, and aiohttp required py3, and also setup failed to run on most of the dependencies. This happens, it is a limitation of the stash pip and ios environment, sometimes you need to do a little extra work. But, we'll try anyway, see if it worked:>>> import discord Traceback (most recent call last): File "<string>", line 1, in <module> File "/private/var/mobile/Containers/Shared/AppGroup/C534C622-2FDA-41F7-AE91-E3AAFE5FFC6B/Pythonista3/Documents/site-packages/discord/__init__.py", line 20, in <module> from .client import Client, AppInfo, ChannelPermissions File "/private/var/mobile/Containers/Shared/AppGroup/C534C622-2FDA-41F7-AE91-E3AAFE5FFC6B/Pythonista3/Documents/site-packages/discord/client.py", line 42, in <module> from .voice_client import VoiceClient File "/private/var/mobile/Containers/Shared/AppGroup/C534C622-2FDA-41F7-AE91-E3AAFE5FFC6B/Pythonista3/Documents/site-packages/discord/voice_client.py", line 64, in <module> from .gateway import * File "/private/var/mobile/Containers/Shared/AppGroup/C534C622-2FDA-41F7-AE91-E3AAFE5FFC6B/Pythonista3/Documents/site-packages/discord/gateway.py", line 30, in <module> import aiohttp File "/private/var/mobile/Containers/Shared/AppGroup/C534C622-2FDA-41F7-AE91-E3AAFE5FFC6B/Pythonista3/Documents/site-packages/aiohttp/__init__.py", line 4, in <module> import multidict # noqa ImportError: No module named 'multidict'
Ok, so sure enough, problem with importing
aiohttp
. Seems like we need a module namedmultidict
. A good first guess is pip...Back to stash, andpip install multidict
.import discord
still fails, no package namedchardet
. Ok, do you sense a pattern?pip install chardet
. Importing discord now saysNameError: name 'errors' is not defined
. That is wierd, since it is on a line that does not even mentionerrors
. Sometimes when you get an import error on package, it gets stuck on a bad state. So we restart pythonista and try again. Nowimport discord
works (in python3 -- discord won't work as written in py2), and client=discord.Client() works too. -
So I've been looking into this, and I've hit a snag. I can't tell whether or not it's insurmountable.
The discord.py library depends on websockets.
Websockets won't install via python 2, so StaSh doesn't install it properly. You can , in theory, run setup.py manually. But when I look at the websockets setup.py file, I see this in the setuptools call:ext_modules = [ setuptools.Extension( 'websockets.speedups', sources=['websockets/speedups.c'], optional=not os.path.exists(os.path.join(root_dir, '.cibuildwheel')), ) ]
Now, to me it looks like this is an optional extension in C, but I'm not sure whether websockets is ever going to install correctly. I don't have any experience with setuptools, so I don't know how SOL Pythonista's going to be when it hits that.
I also can't figure out how to run setup.py (I just get a whole bunch of permission errors), so I haven't been able to verify whether or not it's possible to use websockets. It's even possible that websockets is actually installed properly (despite the issue report that says it can't be installed with pip install if pip is using python 2.x) and the issue with the failed coroutine detection is something else entirely.
Regardless, it looks like it would be a challenge to do anything meaningful with the Discord API using discord.py in Pythonista.
-
It's not possible to run
setup.py
s under Pythonista directly, because of how different the directory structure is compared to a Python installation on a regular Unix or Windows system. (Even on normal systems the recommended way to install packages is topip install
the folder containing thesetup.py
, rather than runningsetup.py install
.) Stash'spip
does some hackery to make mostsetup.py
s work in Pythonista, but since Stash is basically Python 2-only, that isn't an option for Python 3-only packages.If I'm reading the code correctly, the speedups are indeed optional. The
optional=not os.path.exists(...)
part makes it required only when running a CI build (which the library devs have presumably set up to build wheels for PyPI, so they want to force the speedups to be included there).You could try installing the library "the manual way" - install all dependencies somehow (Stash
pip
, or also manually), then find the directory or Python file containing the library's source code and copy that intosite-packages-3
. Assuming the library is used asimport discord
, that would be either a directorydiscord
or a filediscord.py
, most likely located in the same directory as thesetup.py
. -
For what its worth, I have websockets installed in pythonista. I believe it only really needs asyncio, which is included in python 3 on pythonista.
I frankly forget why or how I installed it -- at a minimum, just pip download, then untar.p, or it might be easier to use git clone.
-
Has anyone made any progress on this? I've been trying for the last hour to get discord.py working on the latest Pythonista beta (3.1.1), but haven't had much luck. Currently I'm stuck on getting aiohttp to work. A little bit of googling shows that at one point pythonista beta had aiohttp built in (https://forum.omz-software.com/topic/4456/ui-and-aiohttp), but that doesn't seem to be the case anymore. I was able to install aiohttp using pip from stash, but it seems the imports are messed up, with python complaining about not being able to find parts of the library.
-
- Install Pythonista 3.2 (latest version from the App Store > latest Pythonista beta 3.1.1)
pip install aiohttp
- Extensions are gonna fail, ... but you can ignore them
pip install idna
- Working aiohttp example in Pythonista
with python complaining about not being able to find parts of the library
No crystal ball, always paste what's the problem. If you read the error message you'll see that there's module import error - missing
idna
. -
I followed your instructions, but it still doesn't work. When trying to import
aiohttp
it fails in the__init__.py
file. It looks like it tries to import other parts of the library withfrom .<something> import *
, but it isn't working. The exact message it gives isname 'client' is not defined
. Pythonista says the error is on line 38, but I think it's actually line 29. -
paste the entire traceback...
Also, be sure to quit pythonista and try again. Sometimes if you get an error after starting to import, things get into a stuck state.