Why does my slash command require me to input CTX as a required field?

Viewed 33
import discord
from discord.ext import commands
from datetime import datetime
from discord import Option


class Secondary(commands.Cog):
  def __init__(self, client):
    
    self.client = client
    
    @client.slash_command(description = "")
    async def avatar(self, ctx, user: Option(discord.Member, "Choose a user to mention.")):
      AvatarEmbed = discord.Embed(
        title = f"{user}'s profile image.",
        color = discord.Colour.dark_green()
      )
      AvatarEmbed.set_image(url = user.avatar.url)
      AvatarEmbed.timestamp = datetime.utcnow()
      await ctx.respond(embed = AvatarEmbed, ephemeral = False)
    
def setup(client):
  client.add_cog(Secondary(client))

The code above is what's in my cog.

So I'm trying to make a "avatar" command to display the selected users profile picture. I'm not sure why but it keeps forcing me to enter "ctx" as a field. Here

1 Answers

It's in a cog, but you're registering it using client.slash_command. That ignores the implicit self argument of a bound method and makes it register with self as the context argument, instead of ctx. Simply decorate it with commands.slash_command instead:

@commands.slash_command(description = "")
async def avatar(self, ctx, user: Option(discord.Member, "Choose a user to mention.")):
      ...
Related