Discord rest API:踢出公会成员

问题描述

我正在尝试使用 discord Rest API 和带有 node.js 的“unirest”模块来从我的服务器踢成员:

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 响应。我用的bot是管理员角色,所以可以踢公会成员。

我认为我在请求中犯了一些错误

解决方法

401 表示您没有正确发送您的身份验证凭据。

如果我们查看 Discord Authentication 的文档,我们可以看到他们期望在 Authorization 标头中而不是像您那样在请求中使用机器人令牌。

我们没有使用基本身份验证,因此我们需要手动编写标头。

unirest.delete(request)
  .header('Authorization','Bot ' + botSecret)
  ...

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...