我正在尝试使用Discord Rest API和;unirest";模块与node.js踢成员从我的服务器:
const unirest = require('unirest');
const guildId = "xyz";
const botSecret = "xyz";
const memberId = "xyz"
var request = 'https://discord.com/api/v8//guilds/' + guildId + '/members/' + memberId;
unirest.delete(request).send({"botToken": botSecret}).then((response) => {
console.log(response.body);
}).catch(error =>{
console.log(error);
})
但是,我得到了401: Unauthorized
响应。我使用的机器人具有管理员角色,因此可以将成员踢出公会。
我想我在请求中犯了一些错误。
A 401表示您没有正确发送身份验证凭据。
如果我们查看Discord Authentication的文档,我们可以看到他们希望在Authorization标头中使用bot令牌,而不是像您所做的那样在请求中使用。
我们没有使用基本的auth,所以我们需要手动编写头。
unirest.delete(request)
.header('Authorization', 'Bot ' + botSecret)
...