python - 从 JSON 获取服务器 ID
问题描述
我想从我对如何做感到困惑的 JSON 文件中获取服务器 ID。下面是我当前的 Python 文件
import discord
from discord.ext import commands
import youtube_dl
import json
with open("configs/premium.json") as f:
premium = json.load(f)
def premium(bot, message):
id = message.server.id
return premium.get(id)
class Play:
def __init__(self, client):
self.client = client
@commands.command(pass_context=True)
async def play(self, ctx):
try:
if ctx.message.server.id == premium:
await self.client.say('Premium works')
else:
await self.client.say('Non-Premium Works!')
except Exception as error:
await self.client.say('{}'.format(error))
def setup(client):
client.add_cog(Play(client))
JSON文件
{"serverID":"498054637245693952"}
解决方案
推荐阅读
- android - Android studio onmenuitemclicklistener 函数给出了意想不到的类型规范
- tensorflow - 如何使用 ImageDataGenerator 对读取的文件进行排序
- excel - 获取名称中包含 unicode 字符的文件的文件大小(FileLen() [Excel VBA]
- python - 使用原始数据框从包含 JSON 数据的列中提取数据
- android - 多次更改应用程序中定义的变量的值不起作用 [Android]
- winforms - 检索使用 OS 视觉样式呈现的 WinForms ListBox/ListView 的边框颜色
- angular - 如何使用角度生成多个 PDF 压缩包
- avalara - 特殊税收管辖区的税收计算
- python - PYthon:使用二进制的虚拟环境版本
- python - 如何转换csv文件中的单位值