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.
我不知道如何解决。
您需要使用
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')