1{
2 lib,
3 stdenv,
4 aiohttp,
5 audioop-lts,
6 buildPythonPackage,
7 fetchFromGitHub,
8 ffmpeg,
9 libopus,
10 pynacl,
11 setuptools,
12 withVoice ? true,
13}:
14
15let
16 pname = "discord.py";
17 version = "2.5.2";
18in
19buildPythonPackage {
20 inherit pname version;
21 pyproject = true;
22
23 src = fetchFromGitHub {
24 owner = "Rapptz";
25 repo = "discord.py";
26 tag = "v${version}";
27 hash = "sha256-xaZeOkfOhm1CL5ceu9g/Vlas4jpYoQDlGMEtACFY7PE=";
28 };
29
30 build-system = [ setuptools ];
31
32 dependencies = [
33 aiohttp
34 audioop-lts
35 ] ++ lib.optionals withVoice [ pynacl ];
36
37 patchPhase = lib.optionalString withVoice ''
38 substituteInPlace "discord/opus.py" \
39 --replace-fail "ctypes.util.find_library('opus')" "'${libopus}/lib/libopus${stdenv.hostPlatform.extensions.sharedLibrary}'"
40
41 substituteInPlace "discord/player.py" \
42 --replace-fail "executable: str = 'ffmpeg'" "executable: str = '${lib.getExe ffmpeg}'"
43 '';
44
45 # Only have integration tests with discord
46 doCheck = false;
47
48 pythonImportsCheck = [
49 "discord"
50 "discord.types"
51 "discord.ui"
52 "discord.webhook"
53 "discord.app_commands"
54 "discord.ext.commands"
55 "discord.ext.tasks"
56 ];
57
58 meta = {
59 description = "Python wrapper for the Discord API";
60 homepage = "https://discordpy.rtfd.org/";
61 changelog = "https://github.com/Rapptz/discord.py/blob/v${version}/docs/whats_new.rst";
62 license = lib.licenses.mit;
63 maintainers = with lib.maintainers; [ getpsyched ];
64 };
65}