在Node.js中使用bot创建webhook时出现错误



当我在Node.js中创建一个webhook时,我得到了以下错误。

v18.12.1节点Discord.js version 14.7.1

错误:错误是DiscordAPIError[50035]: Invalid Form Bodyname[BASE_TYPE_REQUIRED]:该字段是必需的

代码:

let channelNumObj = client.channels.cache.get(channelNumVariable);
const webhook = async () => {
try {
if (channelNumObj !== null) {
await channelNumObj
.createWebhook("Snek", {
name: "Snek",
avatar: "http://i.imgur.com/mI8XcpG.jpg",
reason: "Needed a cool new Webhook",
})
.then(() => {
console.log("completed");
});
}
} catch (err) {
console.log(`the error was ${err}`);
}
};
webhook();
});

我找到问题了。问题是我正在查看以前版本的Discord.js文档。更新的文档具有更新的语法。这是我的版本的Discord.js的更新语法,这是在这篇文章的时候的最新版本。

注意语法的变化,其中"Snek"是。

let channelNumObj = client.channels.cache.get(channelNumVariable);
const webhook = async () => {
try {
if (channelNumObj !== null) {
await channelNumObj
.createWebhook({
name: 'Snek',
avatar: "http://i.imgur.com/mI8XcpG.jpg",
reason: "Needed a cool new Webhook",
})
.then(() => {
console.log("completed");
})
.catch(console.error)
}
} catch (err) {
console.log(`the error was ${err}`);
}
};
webhook();
});

最新更新