我想在一条消息中列出变量和键?
@bot.hybrid_command(name="kayitsayi", description="Kayıt sayınızı gösterir")
@app_commands.guilds(discord.Object(id=112233445566))
async def kayitsayi(ctx):
for x in db.staffs.find_one({'guildID': ctx.guild.id}, {"_id": 0, "guildID": 0}):
await ctx.reply(f"<@{x}>" + ": `" + str(db.staffs.find_one({'guildID': ctx.guild.id}, {"_id": 0, "guildID": 0})[x]) + "`")
我试过这个,但是它一个接一个地发送密钥和变量。图片
你能试试吗?
@bot.hybrid_command(name="kayitsayi", description="Kayıt sayınızı gösterir")
@app_commands.guilds(discord.Object(id=112233445566))
async def kayitsayi(ctx):
result = db.staffs.find_one({'guildID': ctx.guild.id}, {"_id": 0, "guildID": 0})
message = ""
for key, value in result.items():
message += f"{key}: {value} "
await ctx.reply(message)