【问题标题】:Discord.py Get the channel name from a Json fileDiscord.py 从 Json 文件中获取频道名称
【发布时间】:2021-07-05 19:29:39
【问题描述】:

我想从 Json 文件中获取频道名称。 但我总是得到频道名称和服务器 ID。 我怎样才能得到频道的名称?

代码:

@client.event
async def on_message(message):
    with open('channel.json', 'r') as f:
        jchannel = json.load(f)

    jchannel[str(message.guild.id)] # What should I change?

    print(f"{jchannel}") # Result = "823878792563916810": "826875862980755476"

Json:

{ “823878792563916810(服务器 ID)”:“826875862980755476(通道 ID)” }

【问题讨论】:

    标签: python json discord discord.py


    【解决方案1】:

    如果我是对的,那么您的实际 JSON 是

    jchannel = { "823878792563916810" : "826875862980755476"}
    

    如果这是jchannel变量中唯一的数据,那么你可以添加

    print(jchannel[list(jchannel)[0]])
    

    【讨论】:

      猜你喜欢
      • 2019-03-25
      • 1970-01-01
      • 2020-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-16
      相关资源
      最近更新 更多