I have been looking at stackoverflow posts and so many places but still can't find the answer to this question that works for me. How do I make discord python slash commands? Following this post :https://stackoverflow.com/questions/71165431/how-do-i-make-a-working-slash-command-in-discord-py#:~:text=import%20discord%20from%20discord.ext%20import%20commands%20create%20you,ids%20in%20which%20the%20slash%20command%20will%20appear. I got the error:
Traceback (most recent call last): File "/home/container/bot.py", line 3, in bot = discord.Bot(command_prefix="!") AttributeError: module 'discord' has no attribute 'Bot'
With this code:
import discord
from discord.ext import commands
bot = discord.Bot(command_prefix="!")
@bot.slash_command(name="first_slash") #Add the guild ids in which the slash command will appear. If it should be in all, remove the argument, but note that it will take some time (up to an hour) to register the command if it's for all guilds.
async def first_slash(ctx):
await ctx.respond("You executed the slash command!")
I tried replacing "bot = discord.Bot" with "bot = commands.Bot" but that didn't work either
The only code I found had no errors was:
import discord
from discord.ext import commands
from discord_slash import SlashCommand, SlashContext
bot = commands.Bot(command_prefix="!")
slash = SlashCommand(bot)
@slash.slash(name="test")
async def _test(ctx: SlashContext):
await ctx.send("Hello World!")
But no slash commands appeared on discord