#๐Ÿ”’ Python Discord Slash commands

17 messages ยท Page 1 of 1 (latest)

compact beacon
#

So im trying to make a bot that accepts slash commands, as i didnt use slash commands before i copied some code from stackoverflow, i want to ask if this code will work since i can't test it now.

import discord
import discord.ext

# setting up the bot

intents = discord.Intents.all() 

# if you don't want all intents you can do discord.Intents.default()

client = discord.Client(intents=intents)
tree = discord.app_commands.CommandTree(client)

# sync the slash command to your server

@client.event
async def on_ready():
   await tree.sync(guild=discord.Object(id=1114436390843846737))
   print("ready")

# make the slash command

@tree.command(name="name", description="description")

async def slash_command(interaction: discord.Interaction):    
   await interaction.response.send_message("command")
frozen sunBOT
#

@compact beacon

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.

compact beacon
#

the code is direcly copied from stackoverflow but i dont know if it works

#

and i cant run it at the moment cause of a issue i will fix later.

#

paste bin link

mint cedar
compact beacon
#

I will fix

mint cedar
#

by removing the guild parameter? adding a guild to the slash command? or copying global commands to that guild?

#

or rather, do you understand how global and guild commands are separated by discord?

compact beacon
mint cedar
compact beacon
steep barn
frozen sunBOT
#
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.