简体   繁体   English

Pycord/discord.py 斜杠命令未显示

[英]Pycord/discord.py slash commands not showing up

Ive never had this issue before.我以前从未遇到过这个问题。 All of my other bots work perfectly, and im convinced its not my source code.我所有的其他机器人都工作得很好,我确信这不是我的源代码。 When I start my bot, i get the following error message:当我启动我的机器人时,我收到以下错误消息:

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'

After the error, the bot starts but doesnt show any slash commands in the servers.错误发生后,机器人会启动但不会在服务器中显示任何斜杠命令。 I am using this invite link:我正在使用这个邀请链接:

https://discord.com/api/oauth2/authorize?client_id=REDACTED&permissions=8&scope=bot%20applications.commands https://discord.com/api/oauth2/authorize?client_id=REDACTED&permissions=8&scope=bot%20applications.commands

here are my bot intents:这是我的机器人意图: 在此处输入图像描述

my code:我的代码:

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"))

Any help is appreciated.任何帮助表示赞赏。 For the life of me I cannot figure out whats happening.对于我的生活,我无法弄清楚发生了什么。

Your interaction parameters are wrong.您的交互参数错误。 Should be:应该:

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"))

Using your code with my changes allowed it to run without throwing an exception and I was able to invoke the lol slash command.使用您的代码和我的更改允许它运行而不会抛出异常,并且我能够调用lol slash 命令。

Slash command docs . 斜线命令文档 Slash commands have the ctx (ApplicationContext) parameter and then other parameters are usually slash command options.斜杠命令有ctx (ApplicationContext) 参数,然后其他参数通常是斜杠命令选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM