[英]Pycord/discord.py slash commands not showing up
我以前从未遇到过这个问题。 我所有的其他机器人都工作得很好,我确信这不是我的源代码。 当我启动我的机器人时,我收到以下错误消息:
Traceback (most recent call last):
File "C:\Users\Overdrive\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\client.py", line 377, in _run_event
await coro(*args, **kwargs)
File "C:\Users\Overdrive\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\bot.py", line 1164, in on_connect
await self.sync_commands()
File "C:\Users\Overdrive\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\bot.py", line 719, in sync_commands
registered_commands = await self.register_commands(
File "C:\Users\Overdrive\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\bot.py", line 588, in register_commands
data = [cmd["command"].to_dict() for cmd in filtered_deleted]
File "C:\Users\Overdrive\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\bot.py", line 588, in <listcomp>
data = [cmd["command"].to_dict() for cmd in filtered_deleted]
File "C:\Users\Overdrive\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\commands\core.py", line 844, in to_dict
"options": [o.to_dict() for o in self.options],
File "C:\Users\Overdrive\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\commands\core.py", line 844, in <listcomp>
"options": [o.to_dict() for o in self.options],
File "C:\Users\Overdrive\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\commands\options.py", line 318, in to_dict
"type": self.input_type.value,
AttributeError: 'NoneType' object has no attribute 'value'
错误发生后,机器人会启动但不会在服务器中显示任何斜杠命令。 我正在使用这个邀请链接:
我的代码:
import discord
from discord.ext import commands
import os
intents=discord.Intents.all()
client=commands.Bot(intents=intents)
@client.event
async def on_ready():
print(f'\n\nSuccessfully logged into Discord as "{client.user}"\nAwaiting user input...')
await client.change_presence(status=discord.Status.online, activity=discord.Activity(type=discord.ActivityType.playing, name="all by myself..."))
@client.slash_command()
async def lol(interaction: discord.Interaction, ctx: discord.ApplicationContext):
await interaction.response.send_message("LOL")
client.run(os.environ.get("TOKEN"))
任何帮助表示赞赏。 对于我的生活,我无法弄清楚发生了什么。
您的交互参数错误。 应该:
import discord
from discord.ext import commands
import os
intents=discord.Intents.all()
client=commands.Bot(intents=intents)
@client.event
async def on_ready():
print(f'\n\nSuccessfully logged into Discord as "{client.user}"\nAwaiting user input...')
await client.change_presence(status=discord.Status.online, activity=discord.Activity(type=discord.ActivityType.playing, name="all by myself..."))
@client.slash_command()
async def lol(ctx: discord.ApplicationContext):
await ctx.response.send_message("LOL")
client.run(os.environ.get("TOKEN"))
使用您的代码和我的更改允许它运行而不会抛出异常,并且我能够调用lol
slash 命令。
斜线命令文档。 斜杠命令有ctx
(ApplicationContext) 参数,然后其他参数通常是斜杠命令选项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.