Slash command não funciona

Question:

can someone help me?

Traceback (most recent call last):
  File "/home/runner/Porto-SeguroBOT-LAUDOS/main.py", line 3, in <module>
    from discord_slash import SlashCommand
ModuleNotFoundError: No module named 'discord_slash'

Repl link:

import discord
from discord.ext import commands
from discord_slash import SlashCommand

# Defina as intenções que o bot usará
ntents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix="/", intents=intents)
slash = SlashCommand(bot, sync_commands=True)

# Crie uma instância do bot com as intenções
bot = discord.Client(intents=intents)

# Inicialize o SlashCommand com a instância do bot
slash = SlashCommand(bot, sync_commands=True)


# Evento que é disparado quando o bot está online
@bot.event
async def on_ready():
    print(f"Bot está online como {bot.user.name}")
    user_id = 539148230840025098  # Substitua pelo ID do usuário desejado
    user = await bot.fetch_user(user_id)
    if user:
        message = "Olá Moonnel, eu acabei de ligar ok"
        await user.send(message)


# Comando 'Teste' transformado em slash command
@slash.slash(name="teste", description="Mostra o status atual do bot")
async def teste(ctx):
    status = bot.user.status
    await ctx.send(f"O status atual do bot é: {status}")


# Rodar o bot
bot.run("TOKEN")

in future, please link the repl. You can do that without exposing your token (which I easily found anyhow) – check your Discord DMs…
In the “Packages” tool, add discord-py-interactions and replace discord_slash in your code with interactions.

2 Likes

Now the problem has changed

    from interactions import SlashCommand
ImportError: cannot import name 'SlashCommand' from 'interactions' (/home/runner/Porto-SeguroBOT-LAUDOS/.pythonlibs/lib/python3.10/site-packages/interactions/__init__.py)
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7f56b3696680>

I wouldn’t use discord-py-interactions; I’d just use the built-in tree commands that already exist within discord.py, lmao.

1 Like

your code is for an outdated version of the interactions library. As stated above you could instead use discord.py which is more actively maintained.

to be clear, discord-py-slash-command/discord-py-interactions is independent now and not a monkey-patch of discord.py

I would still use the built-in tree commands within discord.py; it’s just much easier. Plus, as you said, they’re actively maintained. But honestly, nextcord is even better as it is more actively maintained and not deprecated within voice activities.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.