首页 > 解决方案 > 成员是缺少错误的必需参数

问题描述

您好,所以我正在尝试为我的机器人创建一个代码,该代码可以在不和谐中 ping 特定成员但遇到问题成员是必需的参数,但缺少。我尝试搜索并尝试修复它,但没有任何效果。我对 python 很陌生,不知道如何修复它。

我的代码供参考

import discord, datetime, time
import os
from discord.ext import commands
from discord.ext.commands import Bot

from discord.utils import get
member = 548378867723665409


BOT_PREFIX = ("!")
bot = commands.Bot(command_prefix=BOT_PREFIX)


@bot.command()
async def pong(ctx, member : discord.Member):
  await ctx.send('test')
  
  
  await ctx.send(f"PONG {member}")
  
  


@bot.event
async def on_ready():
    print ("------------------------------------")
    print ("Bot Name: " + bot.user.name)
    print ("------------------------------------")
    
bot.run(os.getenv('TOKEN'))

标签: pythondiscorddiscord.py

解决方案


您收到该错误是因为您没有传递任何成员参数。您的命令应如下所示!pong @member。该成员应在您的消息中提及。我注意到您已经初始化了一个member具有成员 ID 的全局变量。如果您想提及该成员而不是将成员对象作为参数传递,则必须这样做:

memberID = 548378867723665409

@bot.command()
async def pong(ctx):
    member = await bot.fetch_user(memberID)
    await ctx.send(f"PONG {member.mention}")

推荐阅读