Discord.py discontinued? Use Nextcord

Discord.py was a modern, easy to use API wrapper for Discord written entirely in Python. Thanks to its endless list of features, asynchronous support and extensive documentation, it quickly became popular. However, due to lack of interest and personal issues, the original developer has discontinued the project, putting the repository into read-only mode.

Nextcord is a community-maintained fork of Discord.py. The project aims to eventually replace discord.py, with continued support and features and offer the same discord.py API wrapper.

Nextcord Features

Nextcord

As of this writing, the feature list of Nextcord is almost identical to discord.py ones, which are:

  • Modern Pythonic API using async/await syntax
  • Sane rate limit handling that prevents 429s
  • Command extension to aid with bot creation
  • Easy to use with an object-oriented design
  • Optimised for both speed and memory

Nextcord Quick Example

The simple and straightforward example below uses Nextcord to create a bot that respond "Pong" for every "ping" message received.

from nextcord.ext import commands

bot = commands.Bot(command_prefix='$')

@bot.command()
async def ping(ctx):
    await ctx.reply('Pong!')

bot.run('token')

Please note that you should not store your token directly in your code, as it allows anyone with it to access your bot. You may expose it by uploading the code to Github/Gitlab. If you intend to make your code public you should store it securely, a nice alternative is to use environment variables.

Nextcord Guessing Game Example

The piece of code below uses random and nextcord to create a simple guessing game bot, with the $ symbol serves as the bot prefix.

import random
import asyncio

from nextcord.ext import commands

bot = commands.Bot(command_prefix='$')

@bot.command()
async def guess(ctx):
    await ctx.send('Guess a number between 1 and 10.')

    def is_correct(m):
        return m.author == ctx.author and m.content.isdigit()

    answer = random.randint(1, 10)

    try:
        guess = await bot.wait_for('message', check=is_correct, timeout=5.0)
    except asyncio.TimeoutError:
        return await ctx.send(f'Sorry, you took too long it was {answer}.')

    if int(guess.content) == answer:
        await ctx.send('You are right!')
    else:
        await ctx.send(f'Oops. It is actually {answer}.')

bot.run('token')

Nextcord Useful Resources

If you're just starting out with Nextcord, the list of resources below may be helpful to you:

Click to rate this post!
[Total: 9 Average: 4.9]

Leave a Comment