【发布时间】:2021-02-24 19:50:54
【问题描述】:
如何将我的 json 文件中的内容打印到 discord 频道。我有要发布的活动,但我希望它在频道Example Here 中显示活动名称
这是我的 json 文件,事件名称为 Example Here
那么,如何让它看起来像第一个示例?
编辑评论: Click here
第二次编辑评论: CLICK HERE
【问题讨论】:
标签: json discord bots discord.py channel
如何将我的 json 文件中的内容打印到 discord 频道。我有要发布的活动,但我希望它在频道Example Here 中显示活动名称
这是我的 json 文件,事件名称为 Example Here
那么,如何让它看起来像第一个示例?
编辑评论: Click here
第二次编辑评论: CLICK HERE
【问题讨论】:
标签: json discord bots discord.py channel
要使用 json,首先您需要import json。之后,json.loads("file.read()") 并将其存储到变量中。
然后,要发送它的内容,您可以:
result = ""
for i in range(len(variable["eventstitles"])):
result += f"{i + 1}. {variable["eventstitles"][i]}"
之后,await ctx.send(result) 或 await channel.send(result)
点击here了解更多关于抓取特定频道的信息。
编辑:
with open("events.json", "r") as f:
data = json.loads(f.read())
result = ""
for i in range(len(data)):
result += f"{i + 1}. {data['eventstitles'][i]}\n"
await ctx.send(result)
很抱歉给您带来了困惑。
【讨论】: