discord.ext.commands.errors.MissingRequiredArgument:交互是缺少的必需参数

问题描述 投票:0回答:1
import discord
from discord.ext import commands

intents = discord.Intents.default()
intents.message_content = True

bot = commands.Bot(command_prefix='$', intents=intents)


@bot.command()
async def test(interaction: discord.Interaction):
    await interaction.response.send_message(content="Hello!")

bot.run('token')

我尝试过通过交互发送消息,但不起作用。 我收到此错误:

discord.ext.commands.errors.MissingRequiredArgument: interaction is a required argument that is missing.

我不知道如何解决。

python discord discord.py
1个回答
0
投票

您需要使用

discord.ext.commands.Context
对象而不是
discord.Interaction
。喜欢:

import discord

from discord.ext import commands

intents = discord.Intents.default()
intents.message_content = True

bot = commands.Bot(command_prefix='$', intents=intents)


@bot.command()
async def test(ctx):
    await ctx.send("Hello!")

bot.run('token')
© www.soinside.com 2019 - 2024. All rights reserved.