Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 有人能找出为什么每个人的库存都是一样的吗?_Python_Postgresql_Discord.py - Fatal编程技术网

Python 有人能找出为什么每个人的库存都是一样的吗?

Python 有人能找出为什么每个人的库存都是一样的吗?,python,postgresql,discord.py,Python,Postgresql,Discord.py,当有人使用fish命令时,它会做它应该做的事情,它会随机选择一条鱼,并将其放入您的“清单”中。问题是,它不仅把它放在你的,它也把它放在其他人的。所以,如果我得到2条鱼,其他人也一样。此外,elif msg=='view'无论如何都会插入数据,它不会发送“您没有”的消息 kind=[] 鱼=0 级别=1 存储=[] 现金=0 @client.command() 异步def fish(ctx,*,消息:str): 全球现金 全局存储 全球一级 全球种类 全球鱼类 name=ctx.author.na

当有人使用fish命令时,它会做它应该做的事情,它会随机选择一条鱼,并将其放入您的“清单”中。问题是,它不仅把它放在你的,它也把它放在其他人的。所以,如果我得到2条鱼,其他人也一样。此外,elif msg=='view'无论如何都会插入数据,它不会发送“您没有”的消息

kind=[]
鱼=0
级别=1
存储=[]
现金=0
@client.command()
异步def fish(ctx,*,消息:str):
全球现金
全局存储
全球一级
全球种类
全球鱼类
name=ctx.author.name
帮会id=ctx.author.guild.id
user\u id=ctx.author.id
大概率=[‘鲤鱼’、‘鲑鱼’、‘青蛙’]
中等概率=[‘鲶鱼’、‘鳗鱼’、‘大鲈鱼’]
小概率=['Angelfish'、'Blobfish'、'Shark']
cursor.execute(“从用户id=%s和帮会id=%s的钓鱼中选择用户id”,
(用户id、公会id))
result1=cursor.fetchone()
如果result1为无:
cursor.execute(“插入钓鱼(名称、用户id、公会id、鱼、种类、货币、存储、级别)值(%s、%s、%s、%s、%s、%s)”,
(姓名、用户id、公会id、鱼类、种类、现金、储存、等级)
康涅狄格州提交
elif result1不是无:
cursor.execute(“更新钓鱼集fish=%s,种类=%s,存储=%s,级别=%s,其中用户id=%s和公会id=%s”,
(鱼类、种类、储存、等级、用户id、公会id))
康涅狄格州提交
如果msg=='fish':
如果级别==1:
y=random.randint(01100)
如果y>=30:
小=随机选择(大概率)
嵌入=discord.embed(title='Fishing Game',
color=ctx.author.color)
嵌入.set_缩略图(url=ctx.author.avatar_url)
add_字段(name='You catch a common fish',value=f'You catch a{small}')
嵌入.add_字段(name=“Worth:”,value=“$5”)
等待ctx.send(嵌入=嵌入)
种类.附加(小)
鱼类+=1
cursor.execute(“更新钓鱼集种类=%s,钓鱼=%s,其中用户id=%s和帮会id=%s”,
(种类、鱼类、用户id、公会id))
康涅狄格州提交
elif y>=20:
中等=随机选择(中等概率)
嵌入=discord.embed(title='Fishing Game',
color=ctx.author.color)
嵌入.set_缩略图(url=ctx.author.avatar_url)
add_字段(name='You catch a ungeneral fish',value=f'You catch a{medium}')
嵌入.add_字段(name=“Worth:”,value=“$50”)
等待ctx.send(嵌入=嵌入)
种类.附加(中等)
鱼类+=1
cursor.execute(“更新钓鱼集种类=%s,钓鱼=%s,其中用户id=%s和帮会id=%s”,
(种类、鱼类、用户id、公会id))
康涅狄格州提交
艾利夫y
kind = []
fishes = 0
level = 1
storage = []
cash = 0
@client.command()
async def fish(ctx, *, msg: str):
    global cash
    global storage
    global level
    global kind
    global fishes
    name = ctx.author.name
    guild_id = ctx.author.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 user_id 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, money, storage, level) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
                       (name, user_id, guild_id, fishes, kind, cash, storage, level))
        conn.commit()
    elif result1 is not None:
        cursor.execute("UPDATE fishing SET fish = %s, kind = %s, storage = %s, level = %s WHERE user_id = %s AND guild_id = %s",
                       (fishes, kind, storage, level, user_id, guild_id))
        conn.commit()
    if msg == 'fish':
        if level == 1:
            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 += 1
                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()
            elif y >= 20:
                medium = random.choice(medium_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 an uncommon fish', value=f'You caught a {medium}')
                embed.add_field(name="Worth:", value="$50")
                await ctx.send(embed=embed)
                kind.append(medium)
                fishes += 1
                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()
            elif y <= 5:
                large = random.choice(small_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 rare fish!', value=f'You caught a {large}!')
                embed.add_field(name="Worth:", value="$200")
                await ctx.send(embed=embed)
                kind.append(large)
                fishes += 1
                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()
    elif msg == 'view':
        cursor.execute('SELECT fish, kind FROM fishing WHERE user_id = %s AND guild_id = %s',
                       (user_id, guild_id))
        result2 = cursor.fetchone()
        if result2 is not None:
            await ctx.send(f'You have {fishes} fish: {collections.Counter(kind)}')
        elif result2 is None:
            await ctx.send("You don't have any fish yet")