我想从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"}