Search code examples
discorddiscord.py

Discord.py commands wont work after i switched from Nextcord to Discord v2


I just switched to Discord.py v2 after switching using nextcord for 1 or 2 months.

Im having a issue where no commands work like no commands at all

i changed everything from "nextcord" to "discord" and even changed the setups in the cogs to the new async versions

events work, but commands themselves dont

i tried everything i knew but still didnt fix it i tried looking in the discord doc but still couldnt find a soloution

my current code:

import discord
from discord.ext import commands
from discord.ext.commands.core import has_permissions

import asyncio
import os


intents = discord.Intents.default()
intents.members = True

bot = commands.Bot(command_prefix='+', intents=intents)



##COGS


@bot.event
async def on_ready():
    await asyncio.sleep(1)
    print(f'We have logged in as {bot.user}')

    await bot.change_presence(activity=discord.Game(name="in the Mountains"))

@bot.command()
@has_permissions(administrator = True)
async def load(ctx, arg, extension):
    if ctx.author.id == 498839148904579092:
        bot.load_extension(f"{arg}.{extension}")
        embed = discord.Embed(description=f"{extension} module loaded!", colour=discord.Colour.dark_green())
        await ctx.send(embed = embed)
        print(f"{extension} loaded")

@bot.command()
@has_permissions(administrator = True)
async def unload(ctx, arg, extension):
    if ctx.author.id == 498839148904579092:
        bot.unload_extension(f"{arg}.{extension}")
        embed = discord.Embed(description=f"{extension} module unloaded!", colour=discord.Colour.dark_green())
        await ctx.send(embed = embed)
        print(f"{extension} unloaded")
    
@bot.command()
@has_permissions(administrator = True)
async def reload(ctx, arg, extension):
    if ctx.author.id == 498839148904579092:
        bot.reload_extension(f"{arg}.{extension}")
        embed = discord.Embed(description=f"{extension} module reloaded!", colour=discord.Colour.dark_green())
        await ctx.send(embed = embed)
        print(f"{extension} reloaded")

@load.error
async def alreadyloaded(ctx, error):
    if isinstance(error, commands.CommandInvokeError):
        embed = discord.Embed(colour=discord.Colour.dark_red())
        embed.set_author(icon_url="https://cdn.discordapp.com/attachments/883349890921545748/927946906271887430/W0019f8UlvqD3dDC5.png", name="Command Invoke Error! [LOAD]")
        embed.set_thumbnail(url="https://cdn.discordapp.com/attachments/883349890921545748/927946906271887430/W0019f8UlvqD3dDC5.png")
        embed.add_field(name="commands.CommandInvokeError", value=error, inline=True)
        embed.add_field(name="Maybe...", value="The Extension is Non-Exsistant or cannot be Loaded", inline=True)
        embed.set_footer(text="get a list of Modules with [+modules]!")
        await ctx.send(embed = embed, delete_after = 10)
    elif isinstance(error, commands.MissingPermissions):
        await ctx.message.delete()
        await ctx.send(f"{ctx.author.mention}, that Command is Admin only!", delete_after = 3)
        return

@unload.error
async def alreadyunloaded(ctx, error):
    if isinstance(error, commands.CommandInvokeError):
        embed = discord.Embed(colour=discord.Colour.dark_red())
        embed.set_author(icon_url="https://cdn.discordapp.com/attachments/883349890921545748/927946906271887430/W0019f8UlvqD3dDC5.png", name="Command Invoke Error! [UNLOAD]")
        embed.set_thumbnail(url="https://cdn.discordapp.com/attachments/883349890921545748/927946906271887430/W0019f8UlvqD3dDC5.png")
        embed.add_field(name="commands.CommandInvokeError", value=error, inline=True)
        embed.add_field(name="Maybe...", value="The Extension is Non-Exsistant or cannot be Unloaded", inline=True)
        embed.set_footer(text="get a list of Modules with [+modules]!")
        await ctx.send(embed = embed, delete_after = 10)
        return
    elif isinstance(error, commands.MissingPermissions):
        await ctx.message.delete()
        await ctx.send(f"{ctx.author.mention}, that Command is Admin only!", delete_after = 3)
        return

@bot.command()
async def online(ctx):
    print("1")
    await ctx.channel.send("online")
    print("hello")

async def main():
    async with bot:
        #await load_extensions()
        await bot.start("bot auth code")

asyncio.run(main())

Solution

  • Discord.py v2.0 has migrated to api v10, and with this has come the introduction of Intents.message_content, which is disabled by default. This means that you will need to explicitly enable it in code and in the panel, at https://discord.com/developers/applications.

    intents = discord.Intents.default()
    intents.members = True
    intents.message_content = True
    
    bot = commands.Bot(command_prefix='+', intents=intents)