[英]Discord bot command shop not working (sqlite3, Discord.py)
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
))
您實際上並沒有在任何地方運行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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.