[英]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 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.您实际上并没有在任何地方运行shop_buy()
协程,您只是定义了它。 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:如果您想在其他地方使用它,您还可以在命令之外定义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.