Discord.py 生成命令以便只有某些服务器可以执行此操作
我只希望某些服务器能够使用此功能,如下所示 我想知道是否有一种方法可以使它只有特定的服务器ID可以使用这个命令Discord.py 生成命令以便只有某些服务器可以执行此操作,discord.py,Discord.py,我只希望某些服务器能够使用此功能,如下所示 我想知道是否有一种方法可以使它只有特定的服务器ID可以使用这个命令 @bot.command(pass_context = True) async def shittymeme(ctx): api = 'https://api.imgflip.com/get_memes' response = requests.get(api) url = random.choice(response.json()['data']['memes
@bot.command(pass_context = True)
async def shittymeme(ctx):
api = 'https://api.imgflip.com/get_memes'
response = requests.get(api)
url = random.choice(response.json()['data']['memes'])
url = url['url']
await bot.say( embed = discord.Embed(color = 0x0072ff, title = "Here you go").set_image(url = url))
假设您有一个服务器ID的白名单,您可以利用
命令
扩展内置的功能
whitelist = ["id1", "id2"]
def is_in_server_list(server_list):
def predicate(ctx):
return ctx.message.server.id in server_list
return commands.check(predicate)
@bot.command(pass_context = True)
@is_in_server_list(whitelist)
async def shittymeme(ctx):
api = 'https://api.imgflip.com/get_memes'
response = requests.get(api)
url = random.choice(response.json()['data']['memes'])
url = url['url']
await bot.say( embed = discord.Embed(color = 0x0072ff, title = "Here you go").set_image(url = url))