#Slash Commands do not register
1 messages · Page 1 of 1 (latest)
dont forget indentation
and you are still using discord.Client
use discord.client
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
Have u invited ur bot with the application.commands scope enabled?
bot and application.commands
No
It didn´t worked
Yes
The slash commands are now not working in general
Huh
It worked before
It still doesn’t work
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
^ the last thing is incorrect. The other 2 points are correct but your code works fine just how it is.
Are they in a cog that is being loaded?
No
I put then in a different file
Make sure you are on 2.0.0
I am
Is it a cog?
No
But I import the file into the main
It worked I mean
It is stupid, but it worked
Do you load the commands manually?
I don’t understand cogs anyways
Wdym?
Nvm
Can you show your entire main.py (dont show token) and the file with the slash commands that dont work
Thats fine. I dont have much time anyways. :)
@quaint thicket
Ig that you don´t need the config file#
Forget it
I am stupid as hell
@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
I don’t see them at all
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.
Here's the slash cog example.
Cogs, often known as modules or extensions, are used to organize commands into groups. This is useful
Thanks
Please use /close to close this thread if you’ve received the support you needed.
Ok, but it worked before
'Client' object has no attribute 'load_extension'
why are you using discord.Client and discord.Bot?
?tag discord.Bot
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
that's not the tag I was looking for
?tag cogs
No tag cogs found.
?tag cog
No tag cog found.
?tag Cogs
No tag Cogs found.
So you should use discord.Bot for application commands. discord.Client is strictly for events only
Oh
discord.ext.commands.Bot includes application commands and slash commands. discord.ext.bridge.bot combines both application commands and slash commands
Still doesn´t work
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"])```
what about your cog
did you really read the article?
Yes
Ok, but those are not the same
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