Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The signature for command 'ping' is different from the one provided by Discord. #9537

Closed
3 tasks done
cachho opened this issue Aug 24, 2023 · 5 comments
Closed
3 tasks done
Labels
as designed This feature is working as intended

Comments

@cachho
Copy link

cachho commented Aug 24, 2023

Summary

I can't use slash commands because the signature is different.

Reproduction Steps

run minimal reproducible code, in my instance with python3 -m bots.discord-min

Minimal Reproducible Code

import os

import discord
from discord import app_commands
from discord.ext import commands


intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)
tree = app_commands.CommandTree(client)

# Invite link example
# https://discord.com/api/oauth2/authorize?client_id={DISCORD_APPLICATION_ID}&permissions=199680&scope=applications.commands%20bot

class BaseBot:
    def pong(self):
        return "pong!"

class DiscordBot(BaseBot):
    @tree.command(name="ping", description="Simple ping pong command")
    async def ping(self, interaction: discord.Interaction):
        await interaction.response.send_message(self.pong(), ephemeral=True)

    @client.event
    async def on_ready():
        # TODO: Sync in admin command, to not hit rate limits.
        # This might be overkill for most users, and it would require to set a guild or user id, where sync is allowed.
        await tree.sync()
        print("Command tree synced")
        print(f"Logged in as {client.user.name}")

    @tree.error
    async def on_app_command_error(
        interaction: discord.Interaction, error: discord.app_commands.AppCommandError
    ) -> None:
        if isinstance(error, commands.CommandNotFound):
            await interaction.response.send("Invalid command. Please refer to the documentation for correct syntax.")
        else:
            print("Error occurred during command execution:", error)

    def start(self):
        client.run(os.environ["DISCORD_BOT_TOKEN"])


def start_command():
    discord_bot = DiscordBot()
    discord_bot.start()


if __name__ == "__main__":
    start_command()

Expected Results

Return pong

Actual Results

Discord

The application did not respond

Server

Command tree synced
Logged in as EC
Error occurred during command execution: The signature for command 'ping' is different from the one provided by Discord. This can happen because either your code is out of date or you have not synced the commands with Discord, causing the mismatch in data. It is recommended to sync the command tree to fix this issue.

Intents

intents = discord.Intents.default(); intents.message_content = True

System Information

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

Tried waiting 24 hours to sync, just made a new bot and it still happens.

All Privileged Gateway Intents are enabled.

Invite link/permissions is in the code.

I also tried p-i-n-g as a name in case it's the same issue as #9530

edit: added basebot to examplify why I need to use a class.

@cachho cachho added the unconfirmed bug A bug report that needs triaging label Aug 24, 2023
@No767

This comment was marked as off-topic.

@cachho

This comment was marked as off-topic.

@No767

This comment was marked as off-topic.

@Rapptz Rapptz added as designed This feature is working as intended and removed unconfirmed bug A bug report that needs triaging labels Aug 24, 2023
@Rapptz
Copy link
Owner

Rapptz commented Aug 24, 2023

Your command definition is inside a class, which means that it has no way to attach the self binding to the command object. Using cogs or app_commands.Group subclasses is the only supported ways of getting that self binding to work. If you want more help, please join the official discord.py server.

@Rapptz Rapptz closed this as not planned Won't fix, can't repro, duplicate, stale Aug 24, 2023
@cachho
Copy link
Author

cachho commented Aug 24, 2023

Your command definition is inside a class, which means that it has no way to attach the self binding to the command definition. Using cogs or app_commands.Group subclasses is the only supported ways of getting that self binding to work. If you want more help, please join the official discord.py server.

Thanks for the quick feedback, I'll try my luck tomorrow and if I can't figure it out I'll approach you. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
as designed This feature is working as intended
Projects
None yet
Development

No branches or pull requests

3 participants