Discord-py-slash-command not recognised

Question: Hey guys, im having trouble with discord-py-slash-command

ive tried installing, force uninstall restarting and everything else i can think of however i constantly get this error

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

i am new to coding and using python this is all learning for me.

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

intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix="/", intents=intents)
slash = SlashCommand(bot, sync_commands=True)

# Define a slash command
@slash.slash(name="ping", description="Ping command")
async def ping(ctx):
    await ctx.send("Pong!")

# Event handler for when the bot is ready
async def on_ready():
    print(f"We have logged in as {bot.user}")

# Start the bot
def start():
    DISCORD_TOKEN = "DISCORD_TOKEN"  # Replace with your actual Discord token

# Check if the script is being run directly
if __name__ == "__main__":

​​​​​​​​For the question please put what you are asking help for. For the Repl linkplease put the link to your Repl (e.x replit.com/@t72915318/<name of Repl> if there are spaces in the name use dashes: -) for the code snippet and extra code you want to show, put the code you currently have in there inside the backticks ` (usually below the tilda: ~) and same goes for extra code as well, please use this anytime you are showing code. Right next to the first line of backticks put the name of your language (e.x python, java, make sure it is all lower case) Hope this helps :grinning:!

Have you pip installed the python_slash module? If not use this in the shell pip install -U discord-py-slash-command.

yes already satisfied

yeah im not sure if theres an edit function here otherwise i would of gone back to edit it, doh.

Yes there is, click the pencil icon.

1 Like

Didn’t discord_slash got replaced by interactions ?


not sure, im quite new to all of this, just trying to move forward

Let’s make like @SalladShooter said.

Tell us your objective, what are you trying to achieve.

And I suggest to understand every part of the code you are writing.

For example,

I noticed that you wanted to make a ping/pong command.

You can do something like this without the using of slash commands (unless you really want to go by slash comands, but since they are a bit complicated I don’t recommend for beginners).

For example, if you want to create the ping command there is a better way to do it:

@bot.command() #you can use the decorator bot.command (to indicate that this is a command)
async def ping(ctx):
	await ctx.send("pong")

Besides, with the decorator you can add a lot of customization to your commands
aliases, to define a alias letter to your ping command
brief, to make a brief text about your command
descripton, etc.

they are? I’ve always recommended slash commands because they’re more intuitive, performant and don’t require as much parsing and error handling. In py-cord the code needed for slash commands is almost identical to normal commands from discord.py v1.
The only thing to look out for is having to defer if you take too long to respond to a command: a process you can often simplify using functions, and you shouldn’t have to do while learning with simple slash commands.

In an ideal world I’d like to use /commands and sync them to discord so they’re viewable in the command prompt.

For some reason I’m just having a hard time getting my code to recognise that I have infact installed pip discord-py-slash-command

I often find them more complicated because if you want to add options to slash commands you need a bit of tinkering to make it work, while I find the decorator bot.command more intuitive and fluid.

Or maybe I’m just messy in the head :smiling_face_with_tear:

I’ve edited the post best I can hopefully this helps me get to a resolution

1 Like

Did you check if discord-py-slash-command is installed in the packages menu?

Nvm I just check their documentation. Quickstart - interactions.py 4.4.0-beta.1 documentation

As I said before there has been a change in the library and it’s now discord-py-interactions instead of discord-py-slash-command .

Meaning you need to change your code too. A little example:

import interactions

bot = interactions.Client(token="DISCORD_TOKEN")

    description="Ping command",
async def ping(ctx: interactions.CommandContext):
    await ctx.send("Pong!")

changes seem to work and my bot is using the / command but i cant get it to sync with the discord so it shows with the built in /

it could take up to an hour to register since it’s a global command. You can make a change to your code:

bot = interactions.Client(token, debug_scope=...)

Replace ... with the ID of your testing guild (Server)

1 Like

should be https://replit.com/@t72915318/<SLUG>

Traceback (most recent call last):
File “main.py”, line 2, in
from discord.ext import commands, interactions
ImportError: cannot import name ‘interactions’ from ‘discord.ext’ (unknown location)

Instead of , interactions add a new import

import interactions
1 Like