python - 成员是缺少错误的必需参数
问题描述
您好,所以我正在尝试为我的机器人创建一个代码,该代码可以在不和谐中 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'))
解决方案
您收到该错误是因为您没有传递任何成员参数。您的命令应如下所示!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}")
推荐阅读
- javascript - Discord Bot 无法读取未定义的属性“大小”
- javascript - 如何设置触发对象的延迟
- javascript - 合并具有相同值的对象
- mysql - 如何在 mySQL 级联 SELECT 语句中使用“IN”语句?
- selenium - 无法在文本框区域写入新字段
- rust - 结构上意外的第二个可变借用
- python - 如何为 JSONField 创建一个 django 模型,该模型从同一个表的其他字段中获取值?
- c - 在 C 中终止线程
- android - 如何将图标居中在 Stickerview 上?
- swift - 共享扩展 ▸ 应用程序中的 Firebase getDocuments 共享扩展