Reputation: 131
Is there any official support for the new Discord slash commands; if not, how do you use the discord-py-slash-command
module as I couldn't get that to work
I've been spending a while trying to work out how to use the new slash commands and I couldn't find Discord saying how to use it on discord.py.
After a bit of searching I've found a module called discord-py-slash-command
but I couldn't figure out how to use this either.
When I tried to implement it into the main code of my bot nothing happened, so I tried to just run the example they showed on their website here (The top example) without modifying it and that also didn't work, and return this error message:
Traceback (most recent call last):
File "/snap/pycharm-community/224/plugins/python-ce/helpers/pydev/pydevd.py", line 2167, in <module>
main()
File "/snap/pycharm-community/224/plugins/python-ce/helpers/pydev/pydevd.py", line 2034, in main
debugger = PyDB()
File "/snap/pycharm-community/224/plugins/python-ce/helpers/pydev/pydevd.py", line 407, in __init__
self._cmd_queue = defaultdict(_queue.Queue) # Key is thread id or '*', value is Queue
AttributeError: module 'queue' has no attribute 'Queue'
Process finished with exit code 1
Here's my copy and pasted code from their example:
import discord
from discord.ext import commands
from discord_slash import SlashCommand
from discord_slash import SlashContext
bot = commands.Bot(command_prefix="!", intents=discord.Intents.all())
slash = SlashCommand(bot)
@slash.slash(name="test")
async def _test(ctx: SlashContext):
embed = discord.Embed(title="embed test")
await ctx.send(content="test", embeds=[embed])
bot.run(".token.txt")
Upvotes: 0
Views: 2661
Reputation: 49
I've recently been building a bot with discord-py-slash-command. I've figured out that the best way to make a command would be to read their documentation (below).
With your command, what I notice first that I haven't used is ctx: SlashContext
, instead, try using just ctx
. Your script is also probably you used Embeds=[embed]
, and I am not sure how multiple embeds would work, but for a single one, embed=
is lowercase. I'm pretty sure you don't need the content=''
.
The errors seems to be coming from pycharm and not the script itself, maybe try another IDE.
Documentation: https://discord-py-slash-command.readthedocs.io/en/latest/
Option Types (I found this really useful): https://discord-py-slash-command.readthedocs.io/en/latest/discord_slash.model.html?highlight=USER#discord_slash.model.SlashCommandOptionType.USER
My discord is _stefthedoggo#1698
, DM me if you want more help, I have a working bot running solely on discord-py-slash-commands
Upvotes: 0
Reputation: 4743
I'm not very qualified with discord-py-slash-command
but as far as I know, you have to pass some arguments in @slash.slash()
such as description
etc.
guild_ids = [<your guild id>]
slash = SlashCommand(bot, auto_register=True)
@slash.slash(
name="ttest",
description="Sends message.",
guild_ids=guild_ids
)
async def _test(ctx: SlashContext):
embed = discord.Embed(title="embed test")
await ctx.send(content='test', embeds=[embed])
This will work but I don't recommend you to use this module until it's references became more clear. It's so unclear and unhandy also it's syntax is so complicated compared to discord.py
.
Also, you have to enable applications.commands
scope from Discord Developer Portal -> OAuth2 -> Scopes.
Upvotes: 1