Giter Site home page Giter Site logo

nextcord / nextcord Goto Github PK

View Code? Open in Web Editor NEW
1.1K 11.0 188.0 19.99 MB

A Python wrapper for the Discord API forked from discord.py

Home Page: https://docs.nextcord.dev

License: MIT License

Python 100.00%
discord discordpy discordpy-rewrite api-wrapper bot-framework bots discord-api discord-bot discord-py discordbot

nextcord's Introduction

Nextcord

Discord server invite

PyPI version info

PyPI version info

PyPI supported Python versions

Nextcord documentation

Nextcord

A modern, easy-to-use, feature-rich, and async-ready API wrapper for Discord written in Python.

Key Features

  • Modern Pythonic API using async and await
  • Proper rate limit handling
  • Optimised in both speed and memory

Installing

Python 3.8 or higher is required

To install the library without full voice support, you can just run the following command:

# Linux/macOS
python3 -m pip install -U nextcord

# Windows
py -3 -m pip install -U nextcord

Otherwise to get voice support you should run the following command:

# Linux/macOS
python3 -m pip install -U "nextcord[voice]"

# Windows
py -3 -m pip install -U nextcord[voice]

To install additional packages for speedup, run the following command:

# Linux/macOS
python3 -m pip install -U "nextcord[speed]"

# Windows
py -3 -m pip install -U nextcord[speed]

To install the development version, do the following:

$ git clone https://github.com/nextcord/nextcord/
$ cd nextcord
$ python3 -m pip install -U .[voice]

Optional Packages

Please note that on Linux installing voice you must install the following packages via your favourite package manager (e.g. apt, dnf, etc) before running the above commands:

  • libffi-dev (or libffi-devel on some systems)
  • python-dev (e.g. python3.8-dev for Python 3.8)

Quick Example

import nextcord
from nextcord.ext import commands


bot = commands.Bot()

@bot.slash_command(description="Replies with pong!")
async def ping(interaction: nextcord.Interaction):
    await interaction.send("Pong!", ephemeral=True)

bot.run("token")

You can find more examples in the examples directory.

NOTE: It is not advised to leave your token directly in your code, as it allows anyone with it to access your bot. If you intend to make your code public you should store it securely.

Links

nextcord's People

Contributors

abstractumbra avatar alentoghostflame avatar apple502j avatar bijij avatar denvercoder1 avatar diceroll123 avatar emretech avatar gorialis avatar h4ckerxx44 avatar harmon758 avatar hornwitser avatar imayhaveborkedit avatar ioistired avatar jackenmen avatar khazhyk avatar lostluma avatar maskduck avatar ncplayz avatar ooliver1 avatar pre-commit-ci[bot] avatar rapptz avatar sebbylaw avatar skelmis avatar soheab avatar spifory avatar stockermc avatar tag-epic avatar veni-vidi-code avatar vexs avatar xuathegrate avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nextcord's Issues

Welcome screen edit invalid emoji

Traceback (most recent call last):
  File "/home/ooliver/projects/tooty-beta/env/lib/python3.8/site-packages/jishaku/features/python.py", line 145, in jsk_python
    async for send, result in AsyncSender(executor):
  File "/home/ooliver/projects/tooty-beta/env/lib/python3.8/site-packages/jishaku/functools.py", line 109, in _internal
    value = await base.asend(self.send_value)
  File "/home/ooliver/projects/tooty-beta/env/lib/python3.8/site-packages/jishaku/repl/compilation.py", line 140, in traverse
    async for send, result in AsyncSender(func(*self.args)):
  File "/home/ooliver/projects/tooty-beta/env/lib/python3.8/site-packages/jishaku/functools.py", line 109, in _internal
    value = await base.asend(self.send_value)
  File "<repl>", line 3, in _repl_coroutine
    await wc.edit(
  File "/home/ooliver/projects/tooty-beta/env/lib/python3.8/site-packages/nextcord/welcome_screen.py", line 198, in edit
    data = await self._state.http.edit_welcome_screen(self._guild.id, kwargs)
  File "/home/ooliver/projects/tooty-beta/env/lib/python3.8/site-packages/nextcord/http.py", line 336, in request
    raise HTTPException(response, data)
nextcord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In welcome_channels: Invalid emoji for welcome channel.

&jsk py

wc = await _guild.welcome_screen()
await wc.edit(
    welcome_channels=[
        discord.WelcomeChannel(
            channel=_bot.get_channel(802586580766162967),
            description="general",
            emoji=":exclamation:"
        ),
        discord.WelcomeChannel(
            channel=_bot.get_channel(881874888590241832),
            description="general-2",
            emoji=":exclamation:"
        )
    ]
)

this is only an issue when PR 66 is merged

*same happened with <:name:id> custom emojis and raw unicode (:car:)

Imports are broken

#52 fixed imports for ext.commands although this needs to be fixed throughout the entire aliased library

Make it possible to describe command parameters using defaults

Summary

Use function parameter defaults to describe

What is the feature request for?

nextcord.ext.commands

The Problem

Generally, when attempting to describe an argument by either giving it a type, a proper default value, or even some slash command settings in the future you must either do that using explicit code or using the decorator itself.

The Ideal Solution

I suggest an approach similar to fastapi where fields are described using descriptor-like defaults. This is similar to a long-ignored pull request in the original repository except with more functionality and better extendability. It could also allow for accurate typing while keeping all the options.

The Current Solution

This is currently done using annotations. That's generally a great approach but unusable for more complex approaches.
My main problem is with converters. When you use a converter as an annotation it's not actually consistent with the actual type you'll get.

Additional Context

An example of what we had to do before:

def command(
    ctx: commands.Context,
    a: MyCustomConverter,
    b: commands.Greedy[converter_function],
    c: bool = False,
    *,
    rest: commands.clean_content() = ''
):
    ...

And a better solution:

def command(
    ctx: commands.Context,
    a: float = Param(..., converter=MyCustomConverter.convert),
    b: List[int] = Param(..., converter=converter_function, greedy=True),
    c: bool = False,
    rest: str = Param('', rest=True, clean=True)
):
    ...

the ... are literal ellipsis

The functionality should still be consistent with the original pull request

# from 
def command(ctx: commands.Context, member: discord.Member):
    member = member or ctx.author
    ...

# originally suggested
def command(ctx: commands.Context, member: discord.Member = Author()):
    ...

# ideal solution
author = Param(lambda ctx: ctx.member)
def command(ctx: commands.Context, member: discord.Member = author):
    ...

author is now reusable and can even be included in the library itself.

Possible signatures if anyone cares

class Param:
    def __init__(
        self,
        # bot factories and actual types are allowed
        # Field can be a generic type but that will just cause more bad than good
        default: Union[Callable[[commands.Context], Any], commands.Converter, Any] = ...,
        optional: Optional[bool] = None,  # also based on if there is a default argument
        clean: bool = False,  # like commands.clean_content
        greedy: bool = False,  # like commands.Greedy[]
        rest: bool = False,  # like the very hacky keyword only parameter
    ) -> None:
        ...


# this function is the one that will be exported to allow for typing consistency
def Param(
    # in production a 1:1 copy of the  signature params for linters
    default: Union[Callable[[commands.Context], Any], commands.Converter, Any] = ...,
    optional: Optional[bool] = None,
    clean: bool = False,
    greedy: bool = False,
    rest: bool = False,
) -> Any:
    return nextcord.params.Param(default, optional, clean, greedy, rest)

Benefits

  • backward compatible. When a param is not defined the annotation is still used as the converter. When a converter parameter is not provided the annotation is used as the converter.
  • Allows for other types and easier protocols. If the library provides a collection of converters it's easy to work with them.
  • Not just Param has to be used. Other types such as Flag for flags like --flag can be used.
  • This doesn't have to be limited to just normal commands, it can be implemented along with slash commands.
  • And more maybe...

make nextcord.Object work with the int converter

Summary

Nothing else that you told me

What is the feature request for?

The core library

The Problem

Nothing else that you told me

The Ideal Solution

Nothing else that you told me

The Current Solution

No response

Additional Context

No response

Add Migrating to v2.0 and migrating to nextcord

Summary

Improvment for the docs

What is the feature request for?

The documentation

The Problem

There should be a guide on how to port projects over

The Ideal Solution

Something simular to Migrating to v1.0 in the current docs

The Current Solution

No response

Additional Context

No response

Not all intents are added

Summary

there's a lot of missing intents

Reproduction Steps

None

Minimal Reproducible Code

No response

Expected Results

None

Actual Results

None

Intents

none

System Information

None

Checklist

  • I have searched the open issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have removed my token from display, if visible.

Additional Context

No response

Creating a thread returns None

Summary

Creating a thread returns None

Reproduction Steps

  1. Create a public thread
  2. Observe

Minimal Reproducible Code

https://hst.sh/ojowejosed.py

Expected Results

It returns a thread

Actual Results

It returns None

Intents

default

System Information

  • Python v3.9.6-final
  • nextcord v2.0.0-alpha
    • nextcord pkg_resources: v2.0.0a1
  • aiohttp v3.7.4.post0
  • system info: Linux 5.13.9-gentoo #1 SMP Tue Aug 10 11:47:46 CEST 2021

Checklist

  • I have searched the open issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have removed my token from display, if visible.

Additional Context

No response

Plan to incorporate other abandoned modules into Nextcord.

At the moment, all extension modules created by https://github.com/Ext-Creators (such as discord-ext-ipc) are abandoned due to the shutting down of discord.py. We can incorporate these modules into Nextcord in two ways:

  1. Incorporate them as extra modules within this repo, under the ext folder
  2. Have them as separate repos in the organisation

I recommend option 1 as it would make Nextcord one of the largest Discord APIs around and would put us ahead significantly.

RFC system for organisational management

Summary

An RFC system for proposing changes to Nextcord.

What is the feature request for?

The core library

The Problem

As of right now the only way to bring up suggestions and changes is to directly submit an issue or discuss in Discord.

The Ideal Solution

I propose the NEP system (Nextcord Enhancement Proposal). This is very similar to Python's PEPs and Rust's RFCs. These are numbered proposals with detailed information about a planned feature. NEP-000 will explain how NEPs work and NEP-001 (if everything goes to plan) will propose an organisational "council" structure for the project. This will facilitate a system which is far more organised and efficient than that of dpy. Further details will go in NEP-000 (which I intend on drafting should this go through).

The Current Solution

N/A, this is a new system.

Additional Context

NEPs will be found in a separate repo.

broken imports still

Summary

dislash.py, DiscordUtils and other libraries adding on to discord.py do not work with nextcord

Reproduction Steps

I just installed the original latest version of those packages form PyPI and the error occurred

Minimal Reproducible Code

No response

Expected Results

The modules should've imported correctly and the bots using it should have started with no problems.

Actual Results

This error occurred:

File "/home/container/process-aeon/main.py", line 8, in <module>
    from dislash import *
  File "/home/container/.local/lib/python3.8/site-packages/dislash/__init__.py", line 4, in <module>
    from .interactions import *
  File "/home/container/.local/lib/python3.8/site-packages/dislash/interactions/__init__.py", line 1, in <module>
    from .interaction import *
  File "/home/container/.local/lib/python3.8/site-packages/dislash/interactions/interaction.py", line 5, in <module>
    from discord.http import Route
  File "/home/container/.local/lib/python3.8/site-packages/discord/http.py", line 53, in <module>
    from . import __version__, utils
ImportError: cannot import name '__version__' from 'discord' (/home/container/.local/lib/python3.8/site-packages/discord/__init__.py)

Intents

Intents.members

System Information

- Python v3.8.10-final
- nextcord v2.0.0-alpha
    - nextcord pkg_resources: v2.0.0a1
- aiohttp v3.7.3
- system info: Linux 5.4.0-47-generic #51-Ubuntu SMP Fri Sep 4 19:50:52 UTC 2020

Checklist

  • I have searched the open issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have removed my token from display, if visible.

Additional Context

I might have filed a duplicate issue, but please review this issue anyways, the latest commit fixing this issue is broken.

Implement application commands API endpoints

Summary

The library needs to implement the endpoints provided to manage application commands

What is the feature request for?

The core library

The Problem

Currently, Discord provides some endpoints to register, update and delete application commands. This library does not implement any methods to access them through functions as now.

The Ideal Solution

Write some async functions/classes to implement those endpoints: https://discord.com/developers/docs/interactions/application-commands#endpoints

This will be a lot helpful for the application commands developers as it's something that should still go into the core library.

The Current Solution

Using raw HTTP requests made with some undocumented library parts, which is very inconvenient and messy for the end developer.

Additional Context

No response

Suggestion to add nextcord's advantages to readme

Summary

The info in #project-info should be more prominently displayed to keep people interested.

What is the feature request for?

The documentation

The Problem

The readme currently is lacking a lot of info about what makes nextcord unique.

The Ideal Solution

It is important to make sure people know the exact reasons they should use nextcord over alternatives.

It should be mentioned that nextcord is improving the code for ease-of-use and maintainability and the info such as what is found in #project-info could be added to the readme.

image

The Current Solution

No response

Additional Context

No response

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.