python - 我无法弄清楚如何在用户 DND 状态计数器循环中从 json 获取公会 ID 和频道 ID
问题描述
@commands.Cog.listener()
async def on_ready(self):
self.send.start()
@tasks.loop(minutes=10)
async def send(self):
with open('/home/runner/EBOT/info/odi_ch_id.json', 'r') as f:
file = json.load(f)
channelid = file[str(guild.id)]
intchannelid = int(channelid)
guild = self.bot.get_guild(guild.id)
memchannel=guild.get_channel(intchannelid)
online = len(list(filter(lambda m: str(m.status) == "online", guild.members)))
idle = len(list(filter(lambda m: str(m.status) == "idle", guild.members)))
dnd = len(list(filter(lambda m: str(m.status) == "dnd", guild.members)))
await memchannel.edit(name=f" {online} ⛔ {dnd} {idle}")
@send.before_loop
async def before(self):
await self.bot.wait_until_ready()
send.start()
这是一个在线免打扰空闲计数器,每 10 分钟循环一次。我曾经指定公会 ID 和频道 ID,因为我只在 1 个服务器中使用了我的机器人。现在我正在将我的机器人重新制作为多服务器机器人。所以我用公会 ID 和频道 ID提供json 。我希望机器人更新 json 包含的每台服务器中的频道。
Json 看起来像这样
{
"830981882890944512": 880480261899419668
}
左整数是公会 id,右整数是频道 id
解决方案
推荐阅读
- css - 如何使用 flex-end 属性为元素添加边距?
- python-3.x - 在带有标题文本Python / bs4的动态类之后获取文本
- google-chrome - Chrome 上的 Cypress.io 出现“默认为 SameSite cookie”的问题
- vue.js - 为什么事件在同一个元素中只正确触发一次?
- sql - ORACLE SQL 我遇到了一个选择语句的问题,该语句应该显示每个分支的最大余额
- python - 在python中将几个csv文件(超过200个)合并为一个csv文件
- javascript - 通过选择两个相应的选择字段未生成动态链接
- javascript - 在使用 TypeScript 的 Vuex 突变中,对象可能是“未定义”
- ios - AVPlayerViewController 从全屏返回后忽略所有触摸
- plotly.js - Plotly,js - Y 自动缩放