Python Discord bot命令车间不工作(sqlite3,Discord.py)

Python Discord bot命令车间不工作(sqlite3,Discord.py),python,sqlite,discord.py,Python,Sqlite,Discord.py,我试图在我的Discord服务器上实现一个存储,但是命令没有执行,控制台中也没有错误,这段代码被翻译成带有JSON的sqlite 3, 我是sqlite 3和Discord.py的新手 @client.command( pass_context = True ) async def buy(ctx, arg = None): role = arg if role == None: await ctx.send("**Укажите роль, которую хо

我试图在我的Discord服务器上实现一个存储,但是命令没有执行,控制台中也没有错误,这段代码被翻译成带有JSON的sqlite 3, 我是sqlite 3和Discord.py的新手

@client.command( pass_context = True )
async def buy(ctx, arg = None):
    role = arg
    if role == None:
        await ctx.send("**Укажите роль, которую хотите купить.**")

    Aqua=50000
    Red=100000
    Green=150000
    Blue=200000
    Pink=250000
    Gold=500000

    Aqua_role = discord.utils.get( ctx.message.guild.roles, id = 718214683454210088)
    Red_role = discord.utils.get( ctx.message.guild.roles, id = 718215132286550046)
    Green_role = discord.utils.get( ctx.message.guild.roles, id = 718215275618631681)
    Blue_role = discord.utils.get( ctx.message.guild.roles, id = 718216550959677712)
    Pink_role = discord.utils.get( ctx.message.guild.roles, id = 718215775504171049)
    Gold_role = discord.utils.get( ctx.message.guild.roles, id = 718215931406581801)

    async def shop_buy(ctx):
        for row in cursor.execute(f"SELECT money FROM users where id={ctx.author.id}"):

            if role == "Gold":
                if gold_role in ctx.author.roles:
                    await ctx.send(f"{ctx.author.mention}, у вас уже имеется роль {Gold_role}")


                elif row[0] >= Gold:
                    balance = row[0] - summ

                    await ctx.send(embed=discord.Embed(                           
                        description=f" {ctx.author.mention}, покупка прошла успешно ",
                        colour=0x00ff00
                    ))

                    cursor.execute(f'UPDATE users SET money={balance} where id={ctx.author.id}')
                    conn.commit()
                    await ctx.author.add_roles(Gold_role) 

                else:
                    await ctx.send(embed=discord.Embed(                     
                        description=f"**{ctx.message.author.mention}, такой суммы нет у вас на баллансе!**",
                        colour=0xff0000
                        ))

实际上,您并没有在任何地方运行
shop\u buy()
coroutine,您只是定义了它。函数/协同程序不会运行,除非您调用它们

如果您只打算在一个地方使用代码,那么协同程序甚至不是必需的

如果要在其他地方使用,还可以在命令之外定义
shop\u buy()
coroutine:

@client.command()#在重写时自动传递上下文
异步def购买(ctx,arg=None):
角色=arg
如果角色==无:
等待ctx发送(“**Ужжжааа,аааааа,аааааа1072
水=50000
红色=100000
绿色=150000
蓝色=200000
粉红色=250000
黄金=500000
Aqua_role=discord.utils.get(ctx.message.guild.roles,id=718214683454210088)
Red\u role=discord.utils.get(ctx.message.guild.roles,id=71821513228655046)
绿色\-u role=discord.utils.get(ctx.message.guild.roles,id=718215275618631681)
Blue_role=discord.utils.get(ctx.message.guild.roles,id=718216550959677712)
Pink_role=discord.utils.get(ctx.message.guild.roles,id=7182157757504171049)
Gold\u role=discord.utils.get(ctx.message.guild.roles,id=718215931406581801)
异步def商店购买(ctx):
#这里是shop_buy()代码
等待购物(ctx)#你需要打电话给合作伙伴

您实际上并没有在任何地方运行
shop\u buy()
coroutine,您只定义了它。函数/协同程序不会运行,除非您调用它们

如果您只打算在一个地方使用代码,那么协同程序甚至不是必需的

如果要在其他地方使用,还可以在命令之外定义
shop\u buy()
coroutine:

@client.command()#在重写时自动传递上下文
异步def购买(ctx,arg=None):
角色=arg
如果角色==无:
等待ctx发送(“**Ужжжааа,аааааа,аааааа1072
水=50000
红色=100000
绿色=150000
蓝色=200000
粉红色=250000
黄金=500000
Aqua_role=discord.utils.get(ctx.message.guild.roles,id=718214683454210088)
Red\u role=discord.utils.get(ctx.message.guild.roles,id=71821513228655046)
绿色\-u role=discord.utils.get(ctx.message.guild.roles,id=718215275618631681)
Blue_role=discord.utils.get(ctx.message.guild.roles,id=718216550959677712)
Pink_role=discord.utils.get(ctx.message.guild.roles,id=7182157757504171049)
Gold\u role=discord.utils.get(ctx.message.guild.roles,id=718215931406581801)
异步def商店购买(ctx):
#这里是shop_buy()代码
等待购物(ctx)#你需要打电话给合作伙伴

非常感谢,现在我明白我的错误了:)不用担心!如果你觉得这个答案有用,那就去做吧,因为它可以帮助其他有同样问题的人。祝你的机器人好运!快乐编码:^)非常感谢,现在我明白我的错误:)不用担心!如果你觉得这个答案有用,那就去做吧,因为它可以帮助其他有同样问题的人。祝你的机器人好运!快乐编码:^)请不要使用字符串格式/连接将值传递给SQL查询。它容易出错和SQL注入。而是使用驱动程序的占位符,将参数分别传递给
execute()
。有关如何在SQLite中使用
的信息,请参阅。请不要使用字符串格式设置/连接将值传递给SQL查询。它容易出错和SQL注入。而是使用驱动程序的占位符,将参数分别传递给
execute()
。有关如何在SQLite中使用
,请参阅。