I'm trying to implement a store on my Discord server, but the command is not executed also there are no errors in the console, this code was translated to sqlite 3 with JSON, I'm new to sqlite 3 and 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
))
You're not actually running the shop_buy()
coroutine anywhere, you've only defined it. Functions/coroutines won't run unless you call them.
The coroutine isn't even necessary if you're only going to be using the code in one place anyway.
You can also define the shop_buy()
coroutine outside of the command if you want to use it in another place:
@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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.