Python I';i’我想在Discord.py里做一个工作指令,在那里你可以通过回答一个数学问题来赚钱,但我不能让它工作
好的,我正在使用SQLite数据库来实现这个机器人货币系统,我正在尝试做一个新的命令,它会给你一个数学问题,如果你回答正确,你就可以赚钱。现在我的问题是,即使我输入了正确的答案,它也会告诉我我错了。这是我的代码:Python I';i’我想在Discord.py里做一个工作指令,在那里你可以通过回答一个数学问题来赚钱,但我不能让它工作,python,python-3.x,discord.py,discord.py-rewrite,Python,Python 3.x,Discord.py,Discord.py Rewrite,好的,我正在使用SQLite数据库来实现这个机器人货币系统,我正在尝试做一个新的命令,它会给你一个数学问题,如果你回答正确,你就可以赚钱。现在我的问题是,即使我输入了正确的答案,它也会告诉我我错了。这是我的代码: def check(author): def inner_check(message): if message.author != author: return False try: int(mes
def check(author):
def inner_check(message):
if message.author != author:
return False
try:
int(message.content)
return True
except ValueError:
return False
return inner_check
@client.command(pass_context=True)
async def work(ctx):
USER_ID = ctx.message.author.id
no1 = random.randint(1,1000)
no2 = random.randint(1,1000)
answer = no1 + no2
await ctx.send(f'What is **{no1}** + **{no2}**?')
msg = await client.wait_for('message', check=check(ctx.author), timeout=None)
if msg.content == answer:
SQL.execute('update Accounts set balance = balance + ? where user_id = ?', (100, USER_ID))
await ctx.send(f'Good work, {ctx.message.author.mention}. You earned 100 {C_NAME}')
else:
SQL.execute('update Accounts set balance = balance - ? where user_id = ?', (100, USER_ID))
await ctx.send(f"Terrible work, {ctx.message.author.mention}. I'm cutting your paycheck and you lost 100 {C_NAME}")
在
将msg.content
替换为int(msg.content)
或answer
替换为str(answer)
如果答案正确,我们将返回良好的工作。
将msg.content
替换为int(msg.content)
或answer
替换为str(answer)
如果回答是正确的,我们将返回良好的结果。您正在对照int检查字符串。消息内容始终是字符串。您正在对照int检查字符串。消息内容始终是字符串。
if msg.content == answer: