debugging 为什么我的discord机器人不上线?我收到Typeerror消息

qnakjoqk  于 2022-11-14  发布在  其他
关注(0)|答案(1)|浏览(201)

我正在处理一个discord bot,它无法启动。我运行调试器,它给我这个错误: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)

here is the screenshot of the discord bot

r1zhe5dt

r1zhe5dt1#

你的代码第20行有一个错别字。我们都有这种情况。如果你需要更多的帮助,你可以在discord 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)

相关问题