@SpiesWithin This example is correct.
clientis defined with
client = 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 named
multidict. A good first guess is pip...Back to stash, and
pip install multidict.
import discordstill fails, no package named
chardet. Ok, do you sense a pattern?
pip install chardet. Importing discord now says
NameError: name 'errors' is not defined. That is wierd, since it is on a line that does not even mention
errors. Sometimes when you get an import error on package, it gets stuck on a bad state. So we restart pythonista and try again. Now
import discordworks (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.pys 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 to
pip installthe folder containing the
setup.py, rather than running
setup.py install.) Stash's
pipdoes some hackery to make most
setup.pys 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 into
site-packages-3. Assuming the library is used as
import discord, that would be either a directory
discordor a file
discord.py, most likely located in the same directory as the
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
I followed your instructions, but it still doesn't work. When trying to import
aiohttpit fails in the
__init__.pyfile. It looks like it tries to import other parts of the library with
from .<something> import *, but it isn't working. The exact message it gives is
name '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.