discord - 使用 guilds.join 请求让用户加入不和谐公会
问题描述
代码:
let response = await fetch(
`https://discord.com/api/guilds/877414872068001853/members/[user id]`,
{
method: 'PUT',
access_token: `Bearer [user access code]`,
headers: {
"Authorization": `Bot [bot token]`,
"Content-Type": "application/json"
}
}
);
console.log(response);
- 机器人位于我希望用户加入的服务器中
guilds.join
oauth 范围已设置
错误:
Response {
size: 0,
timeout: 0,
[Symbol(Body internals)]: { body: [PassThrough], disturbed: false, error: null },
[Symbol(Response internals)]: {
url: 'https://discord.com/api/guilds/877414872068001853/members/522503261941661727',
status: 400,
statusText: 'Bad Request',
headers: [Headers],
counter: 0
}
}
解决方案
感谢@user15517071
我的access_token不在正文中,而且我使用的“访问令牌”只是来自discord oauth的重定向令牌,所以我需要使用实际的访问令牌discord在获取用户详细信息后为您提供,它可以工作。
{
method: 'PUT',
body: JSON.stringify({
access_token: `Bearer User_AccessToken`,
}),
headers: {
"Authorization": `Bot Bot_Token`,
"Content-Type": "application/json"
}
};
推荐阅读
- r - 如何按第三个变量对图表中的数据进行排序?
- haskell - opaleye 是否支持 upsert / INSERT ON CONFLICT?
- maven - 将不同的存储库组合为一个 Maven 项目
- python - Python正则表达式匹配不包括特定字符的字符串
- python - 循环pytorch中的内存泄漏
- android-studio - 错误:此项目使用 AndroidX 依赖项,但未启用“android.useAndroidX”属性。在 gradle.prop 中将此属性设置为 true
- flutter-layout - 我想在 Flutter 中创建类似的东西
- c - 堆排序,数组的索引从 1 开始而不是 0
- java - 配置带有子项目的 Maven 项目以访问所有 Java 设施
- python-3.x - sns.pairplot 显示密度曲线而不是直方图