使用json python存储频道ID和公会ID

6qfn3psc  于 2021-08-25  发布在  Java
关注(0)|答案(1)|浏览(272)

代码:

def get_channels(client, guild):
    with open('channels.json','r') as f:
        channelss = json.load(f)

    return channelss[str(guild.id)]

@client.event
async def on_ready():
    print("testing...")

@client.command()
async def setreportchannel(ctx, channels: discord.TextChannel):
    with open('channels.json','r') as f:
        channel = json.load(f)

    channel[str(ctx.guild.id)] = int(channels.id)

    with open('channels.json','w') as f:
        json.dump(channel,f,indent=4)

    await ctx.send(f"set the report channel to {channels}")

@client.command()
async def report(ctx, member:discord.Member, *, reason):
    channel = client.get_channel(get_channels)
    await ctx.channel.send(f"{member} has been reported for: {reason}")

json文件:{“850356901232771082”:8503578338816}
问题:它没有在json文件中存储的内容上发送正确的通道,它假设位于用户使用命令setreportchannel设置通道的位置

mdfafbf1

mdfafbf11#

def get_channels(client, guild):
    with open('channels.json','r') as f:
        channelss = json.load(f)

    return channelss[str(guild.id)]

@client.event
async def on_ready():
    print("testing...")

@client.command()
async def setreportchannel(ctx, channels: discord.TextChannel):
    with open('channels.json','r') as f:
        channelss = json.load(f)

    channelss[str(ctx.guild.id)] = int(channels.id)

    with open('channels.json','w') as f:
        json.dump(channelss,f,indent=4)

    await ctx.send(f"set the report channel to {channels}")

@client.command()
async def report(ctx, member:discord.Member, *, reason):
    with open('channels.json', 'r') as f:
        channelss = json.load(f)

    channel_log = ctx.guild.get_channel(channelss[str(ctx.guild.id)])
    await channel_log.send(f"{member} has been reported for: {reason}")

所以有人找到了它并帮助我(不是勺子)。。。问题是我在频道日志中所做的部分,我将频道id而不是公会id放在其中

相关问题