#Slash Commands do not register

1 messages · Page 1 of 1 (latest)

clever bluffBOT
#

Here's the slash cog example.

wild harbor
#

dont forget indentation

wild harbor
#

use discord.client

rustic pike
#

Hello, I added a few slash commands and it worked. I added more slash commands, but they are not registering. I use guild_ids = [976532474895138866] to make it work in my server, but still.

#

This is the code: @bot.slash_command(guild_ids = [976532474895138866], name = "iq", description = "Gets the iq of a user") async def iq(ctx, member: Option(discord.Member, description = "User", required = False)): if member == None: member = ctx.message.user embed=discord.Embed(title=f"IQ Meter", description=f"{member.mention} has an iq of {random.randint(-10, 250)}")

#

I get no error msg

hazy heron
rustic pike
hazy heron
#

Hm

#

Are there two instances running?

#

Of ur bot

rustic pike
hazy heron
#

Hm I'm not sure what could be the issue

#

Try discord.slash_command instead

rustic pike
#

It didn´t worked

hazy heron
#

Hmmm

#

Are u sure they are the correct guild IDs?

rustic pike
#

The slash commands are now not working in general

hazy heron
#

Huh

rustic pike
#

It worked before

rustic pike
#

It still doesn’t work

narrow token
#

Why are you even including the name and guild id?

#

Guild register instantly and you don't need to put the name since it's defined at async def commandname(ctx):

#

Don't quote me cause. It been so long but I think. You might have to put guild id in quotes not brackets not sure though my guess

quaint thicket
#

^ the last thing is incorrect. The other 2 points are correct but your code works fine just how it is.

quaint thicket
rustic pike
quaint thicket
rustic pike
#

I put then in a different file

quaint thicket
#

Make sure you are on 2.0.0

rustic pike
quaint thicket
rustic pike
#

No

#

But I import the file into the main

#

It worked I mean

#

It is stupid, but it worked

quaint thicket
#

Do you load the commands manually?

rustic pike
rustic pike
quaint thicket
#

Nvm

#

Can you show your entire main.py (dont show token) and the file with the slash commands that dont work

rustic pike
#

I will send later?

#

I am on phone rn

quaint thicket
#

Thats fine. I dont have much time anyways. :)

rustic pike
#

@quaint thicket

#

Ig that you don´t need the config file#

#

Forget it

#

I am stupid as hell

unborn wind
#

@rustic pike are the slash commands popping up when you type “/iq” (but just not doing anything) or are you not able to see the slash commands at all

quaint thicket
# rustic pike <@451848182327148554>

you are creating and running 2 separate bots in each of the files. My guess is that the slash commands from 1 bot are being overwritten by the other because they use the same token. I would look into cogs as they are not as hard as you think. Even if you dont understand them it is an easy template.

clever bluffBOT
#

Here's the slash cog example.

quaint thicket
rustic pike
pine depot
#

Please use /close to close this thread if you’ve received the support you needed.

rustic pike
onyx portal
rustic pike
#

wdym?

#

If you are referring to the file I send

#

I already deleted it

onyx portal
#

?tag discord.Bot

quiet lintelBOT
#

A Bot instance cannot be created from discord module directly unless you are using pycord of version 2.0+.

Consider updating pycord using pip install -U py-cord or use this instead: ```py
from discord.ext import commands

bot = commands.Bot() # your args here

onyx portal
#

that's not the tag I was looking for

rustic pike
#

?tag cogs

quiet lintelBOT
#

dynoError No tag cogs found.

rustic pike
#

?tag cog

quiet lintelBOT
#

dynoError No tag cog found.

rustic pike
#

?tag Cogs

quiet lintelBOT
#

dynoError No tag Cogs found.

onyx portal
#

So you should use discord.Bot for application commands. discord.Client is strictly for events only

rustic pike
#

Oh

onyx portal
#

discord.ext.commands.Bot includes application commands and slash commands. discord.ext.bridge.bot combines both application commands and slash commands

onyx portal
#

I don't know your code

#

I also do not know what doesn't work

rustic pike
#
from discord.ext import commands, tasks
import os
import sys
import json
import os
import sys

intents = discord.Intents.all()
intents.members = True
client = commands.Bot(command_prefix="!", intents=intents)
client.remove_command("help")


bot = discord.Client(intents=intents)

if not os.path.isfile("config.json"):
    sys.exit("'config.json' not found! Please add it and try again.")
else:
    with open("config.json") as file:
        config = json.load(file)

@bot.event
async def on_ready():
    print(f'We have logged in as {bot.user}')
    
cogs_list = [
    'moderation',
    'fun'
]

for cog in cogs_list:
    bot.load_extension(f'cogs.{cog}')
          
bot.run(config["Token"])```
onyx portal
#

what about your cog

rustic pike
onyx portal
rustic pike
#

Yes

onyx portal
#

example:

class Greetings(commands.Cog): # create a class for our cog that inherits from commands.Cog
    # this class is used to create a cog, which is a module that can be added to the bot

    def __init__(self, bot): # this is a special method that is called when the cog is loaded
        self.bot = bot

    @commands.command() # create a command
    async def hello(self, ctx): # all methods now must have both self and ctx parameters
        await ctx.send('Hello!')

yours:

class Fun(commands.Cog): 
    def __init__(self, bot): 
        self.bot = bot
        
@bot.slash_command(guild_ids = [976532474895138866], name = 'spoof', description = 'Send a message as another person') # Slash command, Falls ihr das nich wollt nutzt @client.command()!
async def spoof(ctx, user: Option(discord.Member), msg: Option(str, Required=True)):
    embed=discord.Embed(title="Sending message...",
        color=0xff0000)
    await ctx.respond(embed=embed, ephemeral=True)
    webhook = await ctx.channel.create_webhook(name="Spoof Webhook", reason=f"By: {ctx.author} Message: {msg}")
    await webhook.send(username=f"{user.name}", avatar_url=f"{user.avatar.url}", content=f"{msg}")
    await webhook.delete()
#

it is also important that you read the article

#

instead of blindly copying code