【发布时间】:2022-10-20 15:21:56
【问题描述】:
我一直在查看 stackoverflow 帖子和很多地方,但仍然找不到适合我的这个问题的答案。如何制作不和谐的 python 斜线命令? 在这篇文章之后: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。 我得到了错误:
回溯(最近一次通话最后): 文件“/home/container/bot.py”,第 3 行,在 bot = discord.Bot(command_prefix="!") AttributeError:模块'discord'没有属性'Bot'
使用此代码:
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!")我尝试用“bot = commands.Bot”替换“bot = discord.Bot”,但这也不起作用
我发现的唯一没有错误的代码是:
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!")但是不和谐上没有出现斜杠命令
【问题讨论】:
-
这些 sn-ps 都不是 discord.py。 Discord.py Interactions Reference
-
将标签编辑为
pycord,它不是discord.py
标签: python discord bots pycord