【发布时间】:2021-12-28 09:10:56
【问题描述】:
我正在使用 PyMongo 作为我的不和谐机器人的数据库。 我正在制作一个黑名单系统,其中机器人不运行黑名单用户给出的命令。
这是我的代码:
@bot.event
async def on_message(message):
author_id = message.author.id
id = str(author_id)
objInstance = ObjectId(id)
collection.find_one({"_id": ObjectId(id)})
if True:
await message.channel.send("You have been blacklisted from using the bot commands")
else:
await bot.process_commands(message)
@bot.command(aliases=["bl"])
async def blacklist(ctx, * ,member: discord.Member):
if member is None:
await ctx.send("Mention a member to blacklist them!")
else:
post = {"_id": member.id}
collection.insert_one(post)
我收到此错误:
line 38, in _raise_invalid_id
raise InvalidId(
bson.errors.InvalidId: '851756211841925141' is not a valid ObjectId, it must be a 12-byte input or a
24-character hex string
【问题讨论】:
标签: python discord.py pymongo