当成员不在JSON文件中时,Discord.py bot无法发送消息

时间:2020-01-17 06:34:47

标签: python python-3.x discord discord.py

@bot.command()
async def coincount(ctx,*, member: discord.Member = None):
    member = ctx.author if not member else member
    member_id = str(member.id)
    with open('users.json', 'r') as f:
        users = json.load(f)

        coins = users[member_id]['coins']
        if member_id in users:
            if coins > 1:
                await ctx.send(f'{member.mention} has {coins} coins.')
            if coins == 1:
                await ctx.send(f'{member.mention} has {coins} coin.')
        else:
            await ctx.send(f'{member.mention} has no coins.')

没有回溯。如果该成员位于文件中,则该漫游器会发送适当的消息,但如果成员不在文件中,它将不执行任何操作。

0 个答案:

没有答案