我只希望某些服务器能够使用下面显示的此功能。
我想知道是否有办法实现它,所以只有某些服务器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'])
url = url['url']
await bot.say( embed = discord.Embed(color = 0x0072ff, title = "Here you go").set_image(url = url))
答案 0 :(得分:0)
假设您拥有服务器ID白名单,则可以利用commands
扩展程序中内置的Checks
功能。
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))