我正在开发一个discord机器人,但它还没有启动。我运行调试器,它给我这个错误:TypeError: CommandTree.command() got an unexpected keyword argument 'none'
机器人根本不上网。我直接从教程中复制了内容来测试发生了什么,但我似乎无法理解。
import discord
from discord import app_commands
from discord.ext import commands
token='hidden for privacy'
bot=commands.Bot(command_prefix="!", intents=discord.Intents.all())
@bot.event
async def on_ready():
print("Bot is Running")
try:
synced = await bot.tree.sync()
print(f"Synced {len(synced)} Command(s)")
except Exception as e:
print(e)
@bot.tree.command(none="hello")
async def hello(interaction: discord.Interaction):
await interaction.response.send_message(f"Hello {interaction.user.mention}! This is a Slash Command")
ephemeral=True
@bot.tree.command(name="say")
@app_commands.describe(thing_to_say="What should I say?")
async def say(interaction: discord.Interaction, thing_to_say: str):
await interaction.response.send_message(f"{interaction.user.name} said: `{thing_to_say}`")
bot.run(token)
这是discord机器人的屏幕截图
您在代码的第20行中有一个拼写错误。发生在我们最好的人身上。如果你需要更多的帮助,那么你可以在不和谐的RobertK#6151上DM我!
固定代码:
import discord
from discord import app_commands
from discord.ext import commands
token='hidden for privacy'
bot=commands.Bot(command_prefix="!", intents=discord.Intents.all())
@bot.event
async def on_ready():
print("Bot is Running")
try:
synced = await bot.tree.sync()
print(f"Synced {len(synced)} Command(s)")
except Exception as e:
print(e)
@bot.tree.command(name="hello") # instead of @bot.tree.command(none="hello")
async def hello(interaction: discord.Interaction):
await interaction.response.send_message(f"Hello {interaction.user.mention}! This is a Slash Command")
ephemeral=True
@bot.tree.command(name="say")
@app_commands.describe(thing_to_say="What should I say?")
async def say(interaction: discord.Interaction, thing_to_say: str):
await interaction.response.send_message(f"{interaction.user.name} said: `{thing_to_say}`")
bot.run(token)