Pycord-Development / pycord

Pycord is a modern, easy to use, feature-rich, and async ready API wrapper for Discord written in Python
https://docs.pycord.dev
MIT License
2.73k stars 460 forks source link

The prefix command no longer works after the update. #1038

Closed MrSnifo closed 2 years ago

MrSnifo commented 2 years ago

Summary

The problem is that the slash command and the prefix command are working fine on 2.0.0a after I updated to 2.0.0b4 only the slash command is working.

Reproduction Steps

bot.py


from abc import ABC
from discord.ext import commands

class Bot(commands.Bot, ABC):
    def __init__(self) -> None:
        super().__init__(pm_help=False,
                         self_bot=False,
                         case_insensitive=True,
                         help_command=None)
        # For making the interaction Button works even after restart.
        self.persistent_views_added = False

    def setup(self) -> None:
        self.load_extension(f"test")

    async def get_prefix(self, message) -> list:
        return commands.when_mentioned_or(*"!")(self, message)

    async def on_connect(self) -> None:
        print(f"Connected as {self.user} with ID {self.user.id}")
        #  prevent overriding the on_connect function that lead to disable slash commands.
        await super().on_connect()

    async def on_ready(self) -> None:
        print(f"Bot is now ready with latency of {self.latency * 1000:,.0f}ms")
        if not self.persistent_views_added:
            self.persistent_views_added = True

    def run(self) -> None:
        self.setup()
        super().run(token="Token Here", reconnect=True)

Bot().run()

Test cog

# -*- coding: utf-8 -*-

from discord.ext import commands
from discord.commands import slash_command, ApplicationContext

class Test(commands.Cog):
    __slots__ = "bot"

    def __init__(self, bot) -> None:
        self.bot = bot

    @slash_command(name="test1", description="Testing", guild_ids=[...]) # Don't miss this
    async def slash(self, ctx: ApplicationContext) -> None:
        await ctx.respond(content="Slash command Works!")

    @commands.guild_only()
    @commands.command(name="test2")
    async def prefix(self, ctx: commands.Context) -> None:
        await ctx.send("Prefix command Works!")

def setup(bot) -> None:
    bot.add_cog(Test(bot))

Minimal Reproducible Code

Unknown

Expected Results

The prefix command and the Slash command are working correctly.

Actual Results

Only Slash command works, After switching to 2.0.0a everything works fine.

Intents

all

System Information

Checklist

Additional Context

No response

krittick commented 2 years ago

Is your bot verified without the message content intent by any chance? If so, we introduced a workaround to use version 9 of the API to avoid this in #1032.

MrSnifo commented 2 years ago

No, I'm using a normal unverified bot, and on 2.0.0a it raises Command "blablabla" is not found but 2.0.0b4 it does not. And I really need the new Modal update (await, stop). so I can't switch back to the old version.

MrSnifo commented 2 years ago

Solved, by switching to API V9

MrSnifo commented 2 years ago

After reading the V10 changes, message content intent can be enabled in the discord app so you can use the V10, My bot is only connected to one server so after I have enabled it, Nothing happened it still has the same issues.

UP929312 commented 2 years ago

The reason this broke over the update is because the default api version the library used is now V10, which doesn't send message contents (for the most part), an update was posted to allow the user to more easily change which api version is being used, so you can change it back to V9 and it should work again.

MrSnifo commented 2 years ago

The reason this broke over the update is because the default api version the library used is now V10, which doesn't send message contents (for the most part), an update was posted to allow the user to more easily change which api version is being used, so you can change it back to V9 and it should work again.

You can send message content if you enable message content intent in discord apps so V10 can work properly, but the problem is I enabled it, and still not working.

MrSnifo commented 2 years ago

Solved, by adding:

intents = discord.Intents.all()

super().__init__(pm_help=False,
                 self_bot=False,
                 case_insensitive=True,
                 help_command=None,
                 intents=intents)