接入教程
1. 访问Améthyste官网注册获取API密钥
2. 选择需要的图像生成端点(如/生成/欢迎)
3. 在Discord机器人代码中调用API
4. 传入用户ID和自定义参数
5. 接收并处理返回的图像URL
6. 将生成的图像发送到Discord频道
使用Python生成Discord欢迎图像
import requests
url = 'https://api.amethyste.moe/generate/welcome'
headers = {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
}
data = {
'username': 'DiscordUser123',
'avatar': 'https://example.com/avatar.png',
'background': 'default'
}
response = requests.post(url, headers=headers, json=data)
if response.status_code == 200:
with open('welcome.png', 'wb') as f:
f.write(response.content)
print('Image saved successfully')
else:
print(f'Error: {response.status_code}')
print(response.text)
使用PHP生成等级卡片图像
<?php
$api_url = 'https://api.amethyste.moe/generate/rankcard';
$api_key = 'YOUR_API_KEY';
$data = array(
'username' => 'PHPUser',
'level' => 25,
'xp' => 1250,
'avatar' => 'https://example.com/user_avatar.jpg',
'theme' => 'dark'
);
$options = array(
'http' => array(
'header' => "Authorization: Bearer $api_key\r\n" .
"Content-Type: application/json\r\n",
'method' => 'POST',
'content' => json_encode($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($api_url, false, $context);
if ($result !== false) {
file_put_contents('rank_card.png', $result);
echo 'Image generated successfully';
} else {
echo 'Failed to generate image';
}
?>
使用JavaScript生成Discord资料卡
const fetch = require('node-fetch');
async function generateProfileCard() {
const url = 'https://api.amethyste.moe/generate/profile';
const apiKey = 'YOUR_API_KEY';
const requestData = {
username: 'JS_User',
discriminator: '1234',
avatar: 'https://example.com/profile_pic.jpg',
status: 'online',
badges: ['developer', 'supporter']
};
try {
const response = await fetch(url, {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(requestData)
});
if (response.ok) {
const buffer = await response.buffer();
require('fs').writeFileSync('profile_card.png', buffer);
console.log('Profile card generated successfully');
} else {
console.error(`Error: ${response.status}`);
console.error(await response.text());
}
} catch (error) {
console.error('Request failed:', error);
}
}
generateProfileCard();
常见问题
如何获取API密钥?
请访问Améthyste官方网站并注册账户,在控制面板中可以生成和管理您的API密钥。免费套餐提供有限的调用次数,高级套餐提供更多功能和更高的调用限制。
生成的图像格式支持哪些?
API默认生成PNG格式的图像,支持透明背景。所有生成的图像都是高质量的,适合在Discord和其他平台上使用。如果需要其他格式,可以通过参数指定或后续转换。
API调用有什么限制?
免费套餐每分钟最多10次调用,每天最多100次调用。付费套餐根据等级提供更高的限制。建议在代码中添加适当的错误处理和重试逻辑,以应对速率限制的情况。
Aitishiku.com