首页 > 解决方案 > Why python if command doesnt work correctly?

问题描述

@Bot.command()
async def kod(ctx,discordid):
    objects = Code.manager(db)
    code_list = list(objects.all())
    i = 1
    while i <= len(code_list):
        usercode = objects.get(i)
        usercode = usercode.__dict__
        id = usercode.get('discord_id')
        print(discordid)
        print(id)
        if discordid == id:
            await ctx.send("worked")
        i = i + 1

I have problem with if command.you can see the result of the print(id) and print(discordid) code here:

806114153915875378
806114153915875378

You can see that discordid and id are the same. But

if discordid == id:
    await ctx.send("worked")

Code doesnt work correctly and bot doesnt send message.There isnt a error printed at terminal.

标签: pythondiscord.py

解决方案


试试这个程序

if str(discordid) == str(id):
    await ctx.send("worked")

推荐阅读