我试图将此工作代码转换为斜杠命令--但它不起作用
我试图转换的代码:(最小)
import discord
from discord.ext import commands
from discord import Intents
import animec
intents = Intents.all()
intents.members = True
bot = commands.Bot(command_prefix='$', intents=intents)
@bot.command()
async def anime(ctx, *, query):
anime = animec.Anime(query)
embedanime = discord.Embed(title= anime.title_english, url= anime.url, description= f"{anime.description[:1000]}...", color=0x774dea)
await ctx.send(embed=embedanime)
bot.run(TOKEN)我试着用和其他斜杠命令一样的方式来做,但是它没有响应。
import discord
from discord.ext import commands
from discord import Intents, Option
import animec
intents = Intents.all()
intents.members = True
bot = commands.Bot(command_prefix='$', intents=intents)
@bot.slash_command(name="anime", description="Search for an anime on MAL", guild=discord.Object(id=824342611774144543))
async def anime(interaction: discord.Interaction, *, search: Option(str, description="What anime you want to search for?", required=True)):
anime = animec.Anime(search)
embedanime = discord.Embed(title= anime.title_english, url= anime.url, description= f"{anime.description[:1000]}...", color=0x774dea)
await interaction.response.send_message(embed=embedanime)
bot.run(TOKEN)当我尝试使用斜杠命令时所遇到的错误:
Application Command raised an exception:
NotFound: 404 Not Found (error code: 10062):
Unknown interaction发布于 2022-10-05 00:51:38
首先,pycord使用上下文并为guild_ids获取整数ID。
对于错误,命令可能需要超过3秒才能响应(可能是因为animec.Anime(search))。如果交互时间超过3秒,可以使用await ctx.defer()延迟响应。
所以你应该做的是:
@bot.slash_command(name="anime", description="Search for an anime on MAL", guild_ids=[824342611774144543])
async def anime(ctx: discord.ApplicationContext, *, search = Option(str, description="What anime you want to search for?", required=True)):
await ctx.defer()
anime = animec.Anime(search)
embedanime = discord.Embed(title=anime.title_english, url=anime.url, description=f"{anime.description[:1000]}...", color=0x774dea)
await ctx.respond(embed=embedanime)https://stackoverflow.com/questions/73936888
复制相似问题