回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我的问题是,当我使用一次命令时,它会给我一条鱼,但如果我再次使用,它会用最新的鱼替换以前的鱼。它应该将自己添加到列表中,而不是覆盖它。下面是清单。每次我使用该命令时,都会在该列表中添加一条鱼</p>
<pre><code>async def fish(ctx, *, msg: str):
level = 1
storage = []
cash = 0
kind = []
fishes = 0
name = ctx.author.name
guild_id = ctx.guild.id
user_id = ctx.author.id
large_chance = ['Carp', 'Salmon', 'Frog']
medium_chance = ['Catfish', 'Eel', 'Large Bass']
small_chance = ['Angelfish', 'Blobfish', 'Shark']
cursor.execute("SELECT fish FROM fishing WHERE user_id = %s AND guild_id = %s",
(user_id, guild_id))
result1 = cursor.fetchone()
if result1 is None:
cursor.execute(
"INSERT INTO fishing (name, user_id, guild_id, fish, kind) VALUES (%s, %s, %s, %s, %s)",
(name, user_id, guild_id, fishes, kind))
conn.commit()
elif result1 is not None:
if msg == 'fish':
y = random.randint(0, 100)
if y >= 30:
small = random.choice(large_chance)
embed = discord.Embed(title='Fishing Game',
color=ctx.author.color)
embed.set_thumbnail(url=ctx.author.avatar_url)
embed.add_field(name='You caught a common fish', value=f'You caught a {small}')
embed.add_field(name="Worth:", value="$5")
await ctx.send(embed=embed)
kind.append(small)
fishes = result1[0] + 1
await ctx.send(kind)
cursor.execute("UPDATE fishing SET kind = %s, fish = %s WHERE user_id = %s AND guild_id = %s",
(kind, fishes, user_id, guild_id))
conn.commit()
</code></pre>