pycord icon indicating copy to clipboard operation
pycord copied to clipboard

'SlashCommand' object is not callable

Open rpop0 opened this issue 5 years ago • 8 comments

Summary

This issue is about a warning that happens when trying to use slash commands using the @bot.slash_command() decorator.

Reproduction Steps

Trying to use any kind of slash command. This issue also happens with the code example from the readme of the github page.

Minimal Reproducible Code

@bot.slash_command()
async def hello(ctx, name: str = None):
    name = name or ctx.author.name
    await ctx.send(f"Hello {name}!")


### Expected Results

No warnings given for the slash command decorator.

### Actual Results

![image](https://user-images.githubusercontent.com/38384209/132031304-d14c5750-80af-4c13-a44a-31cc14da159f.png)


### Intents

intents = discord.Intents.all()

### System Information

- Python v3.9.1-final
- pycord v2.0.0-alpha
    - pycord pkg_resources: v2.0.0a3785+g16dcf2c6
- aiohttp v3.7.4.post0
- system info: Windows 10 10.0.19041


### Checklist

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

### Additional Context

_No response_

rpop0 avatar Sep 03 '21 15:09 rpop0

Unable to reproduce. Could you please ask this question in a help channel in the Pycord server https://discord.gg/WCVGK4p7 and ping me (Zeffo#0393)?

zeffo avatar Sep 04 '21 08:09 zeffo

Unable to reproduce. What did you define your bot variable as? Can you also show your imports, please?

BruceCodesGithub avatar Sep 04 '21 15:09 BruceCodesGithub

Imports:

import discord
from discord.ext import commands, tasks
from database_managers.CaseManager import CaseManager
from database_managers.LawyerManager import LawyerManager
from database_managers.JudgeManager import JudgeManager
from database_managers.ReminderManager import ReminderManager
from web_handlers.MainForumScraper import MainForumScraper
from web_handlers.MainForumRegistryEditor import MainForumRegistryEditor
from config import bot_token, main_forum_name, main_forum_pass, guild_id
from Views.TakeCase import TakeCase
from Views.ReloadCases import ReloadCases
import re
from datetime import datetime
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

Bot definition:

class Bot(commands.Bot):
    def __init__(self):
        super().__init__(command_prefix=commands.when_mentioned_or('.'), intents=intents)
        self.guild = None

    def get_channel_on_guild(self, channel_name):
        channel_guild = discord.utils.get(self.get_all_channels(), name=channel_name).guild
        channel_id = discord.utils.get(self.get_all_channels(), name=channel_name).id
        return channel_guild.get_channel(channel_id)

    @staticmethod
    async def on_ready():
        print("Bot is up.")
        # three_hour_refresh.start()
        reminder_thread.start()
        renewal_loop.start()

@BruceCodesGithub

rpop0 avatar Sep 04 '21 18:09 rpop0

I should also mention that I'm on the master branch.

rpop0 avatar Sep 04 '21 18:09 rpop0

yeah same. regardless of what kind of bot definition I use (discord.Bot and commands.Bot) I still get the warning that it's not callable, tho when ran it works

Luckolite avatar Sep 04 '21 20:09 Luckolite

This is also an issue for user_command, message_command.

So I've been really trying to see what causes this issue exactly and after looking in the code a bit and trying to understand it, I came to the conclusion that this warning was caused by the return type hinting of slash_command in bot.py, as upon removal of the type hinting for the return type, the warning went away.

rpop0 avatar Sep 06 '21 23:09 rpop0

A fix for this issue can be found in pull request #125

rpop0 avatar Sep 07 '21 15:09 rpop0

This should have been fixed.

CodeWithSwastik avatar Sep 08 '21 03:09 CodeWithSwastik