Discord bot命令商店不起作用(sqlite3,Discord.py)

时间:2020-06-04 22:49:10

标签: 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("**Укажите роль, которую хотите купить.**")

    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
                        ))

1 个答案:

答案 0 :(得分:0)

您实际上并没有在任何地方运行shop_buy()协程,而只是定义了它。除非您调用函数/协程,否则它们将不会运行。

如果您只打算在一个地方使用代码,甚至不需要协程。

如果要在其他地方使用它,也可以在命令外部定义shop_buy()协程:

@client.command() # context is automatically passed in rewrite
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):
        # shop_buy() code here

    await shop_buy(ctx) # you need to call the coroutine