#πŸ”’ Discord Slash Commands

22 messages Β· Page 1 of 1 (latest)

quick dew
#

Hello, so i started a discord bot project for fun but i have one issue, the new slash command that i add wont show in discord, in terminal it says "Synced 3 commands" but when i type "/" in discord i only see the "remove" command but when i go to settings --> integrations --> manager bot i see all 3 commands over there

bot.py

import discord
from discord.ext import commands
import os
import json
import time
import asyncio

intents = discord.Intents.all()

client = commands.Bot(command_prefix='!', intents=intents)

with open("config.json", "r+", encoding="utf-8") as f:
    config = json.load(f)
    token = config["token"]

@client.event
async def on_ready():
    print(f"[!] {time.strftime('%Y-%m-%d - %H:%M')}: bot is online")
    print(f"[!] Logged in as: {client.user} - {client.user.id}")

@client.event
async def on_guild_join(guild: discord.Guild):
    await client.tree.sync(guild=guild)

@client.event
async def setup_hook():
    logs = await client.tree.sync()
    print(f"[!] Synced {len(logs)} commands")

async def loadcogs():
    for filename in os.listdir('./Commands'):
        if filename.endswith('.py'):
            await client.load_extension(f'Commands.{filename[:-3]}')

async def startup():
    async with client:
        await loadcogs()
        await client.start(token)

asyncio.run(startup())

economy.py

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


class Economy(commands.Cog):
    def __init__(self, client):
        self.client = client

    @app_commands.command(name="addmoney", description="Command to add money")
    async def add_money(self, interaction: discord.Interaction):
        await interaction.response.send_message("test command...")
        return
    
    @app_commands.command(name="remove", description="Command to remove money")
    async def remove_money(self, interaction: discord.Interaction):
        await interaction.response.send_message("test command...")
        return
    
    @app_commands.command(name="balance", description="Command to check balance")
    async def balance(self, interaction: discord.Interaction):
        await interaction.response.send_message("test command...")
        return

async def setup(client):
    await client.add_cog(Economy(client))
opaque forgeBOT
#

@quick dew

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

quick dew
quick dew
# quick dew

the description of the remove command didn't even change πŸ’€

sour ferry
#

press ctrl+R to reload discord

#

the discord client doesn't update command lists on a regular basis because they change so infrequently

#

you need to reload discord to force them to update

quick dew
#

oh

#

thanks

sour ferry
#

np

quick dew
#

but i have one question

quick dew
# sour ferry np

is it good on how im calling the tree sync? i don't want to have a crash that forces my bot to reboot this can lead to unnecessary API requests on startup and maybe i will get rate-limited

sour ferry
#

To be honest, I don't know. I've heard so many different opinions...

#

The correct answer is that you only "need" to sync commands after chaning them

#

but that's quite impractical to do manually

#

I think it's probably fine to just do what you're doing until you run into issues

#

if you get rate limited, just wait a few minutes and run it again

quick dew
#

alrighty

#

ty

opaque forgeBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.

#

πŸ”’ Discord Slash Commands