我如何在不和谐的情况下改变虚荣心的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 }发布于 2022-09-21 20:26:03
我不明白为什么需要setTimeout,但是在请求中使用了错误的HTTP方法:正确的方法是PATCH。
此外,在Fetch API中,payload不是一个选项,而是使用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",
}),
});https://stackoverflow.com/questions/73193170
复制相似问题