I can't use a slash command on my discord bot

Question:
can someone fix this import so it imports slash commands
Repl link:
https://replit.com/@StevenBrixie/discord-bot?v=1
Code snippet

from discord_slash import SlashCommand, SlashContext

I believe that discord bots in python now use the Interactions as slash commands.

Try to take a look at their documentation.

Now, let’s create our first slash command:

import interactions

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

@bot.command(
    name="my_first_command",
    description="This is the first command I made!",
    scope=the_id_of_your_guild,
)
async def my_first_command(ctx: interactions.CommandContext):
    await ctx.send("Hi there!")

bot.start()

https://discord-py-slash-command.readthedocs.io/en/latest/quickstart.html

5 Likes
from discord.ext import commands
import discord

bot = discord.AutoShardedClient(
    intents=discord.Intents(
        guilds=True,
        members=True,
        bans=True,
        emojis=True,
        voice_states=True,
        messages=True,
        reactions=True,
        message_content=True, # discord.Intents.all() works fine as well :].
    ), shard_count=1)
tree = discord.app_commands.CommandTree(bot)


@bot.event
async def on_ready():
    await tree.sync() # sync slash commands.
    await bot.change_presence(
        status='dnd',
        activity=discord.Activity(
            type=discord.ActivityType.watching, 
            name="..."
            )
        )
    
    print(f'{bot.user} | up!')

@tree.command(name='test', description='test command')
async def test(interaction: discord.Interaction, message: str=''):
    if message:
        await interaction.response.send_message(content=f'`{message}`')
    await interaction.response.send_message(content=f'`test`')

bot.run(token='', reconnect=True)

for me, I have replit sign into my bot account, then I give it something to do, which is much easier,
and @Sky solved it perfectly, so thats good.

1 Like