使用节点发出请求.JS改变虚荣的矛盾



如何更改Discord中的虚荣url代码?我当前的代码返回401错误。

代码:

const fetch = require("node-fetch");
setTimeout(async () => {
await fetch('https://www.discord.com/api/v9/guilds/serverID/vanity-url', {
method: 'POST',
headers: { 'Authorization': 'Bot ' + client.token, 'Content-Type': 'application/json'},
payload: JSON.stringify({
"code":"terbo1"
})
})
.then(async res => await res.json())
.then(json => { console.log(json);});

响应:

{ message: '401: Unauthorized', code: 0 }

我不明白为什么您需要setTimeout,但是您在请求中使用了错误的HTTP方法:正确的方法是PATCH

此外,payload不是Fetch API上的选项,请改用body

const fetch = require("node-fetch");
const endpoint = `https://www.discord.com/api/v10/guilds/${SERVER_ID}/vanity-url`;
await fetch(endpoint,{
method: "PATCH",
headers: {
Authorization: `Bot ${client.token}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
code: "terbo1",
}),
});

编辑:截至2022年12月1日(12/01/22(,Discord现已禁用机器人";操纵";这个请求,但是,上面的脚本可以在User-Account上使用,这样做有被禁止的风险,所以不建议使用,使用风险自负。

最新更新