discord.js v14创建通道



我试图创建一个通道,但总是出错。我不知道该怎么修。

不要注意";req[0]"在";代码";它来自数据库,与问题无关,因为它在v13 中工作

"看起来你的帖子大部分都是代码;请添加更多详细信息"我不知道我能得到什么来了解更多的细节。哈哈。

对不起,英语不是我的母语。

错误:

throw new DiscordAPIError.DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData);
^
DiscordAPIError[50035]: Invalid Form Body
name[BASE_TYPE_REQUIRED]: This field is required
at SequentialHandler.runRequest (/root/project/node_modules/@discordjs/rest/dist/lib/handlers/SequentialHandler.cjs:293:15)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.queueRequest (/root/project/node_modules/@discordjs/rest/dist/lib/handlers/SequentialHandler.cjs:99:14)
at async REST.request (/root/project/node_modules/@discordjs/rest/dist/lib/REST.cjs:52:22)
at async GuildChannelManager.create (/root/new ascension/node_modules/discord.js/src/managers/GuildChannelManager.js:145:18) {
rawError: {
code: 50035,
errors: {
name: {
_errors: [
{
code: 'BASE_TYPE_REQUIRED',
message: 'This field is required'
}
]
}
},
message: 'Invalid Form Body'
},
code: 50035,
status: 400,
method: 'POST',
url: 'https://discord.com/api/v10/guilds/873350117124628552/channels',
requestBody: {
files: undefined,
json: {
name: undefined,
topic: undefined,
type: undefined,
nsfw: undefined,
bitrate: undefined,
user_limit: undefined,
parent_id: undefined,
position: undefined,
permission_overwrites: undefined,
rate_limit_per_user: undefined,
rtc_region: undefined,
video_quality_mode: undefined
}
}
}
Node.js v18.3.0

代码:

action.guild.channels.create(`hello`, {
type: "GUILD_TEXT",
parent: cat[0].ID,
permissionOverwrites: [
{
id: bot.user.id,
allow: ['VIEW_CHANNEL', "MANAGE_CHANNELS"]
},
{
id: action.user.id,
allow: ["VIEW_CHANNEL"]
},
{
id: req[0].ID,
deny: ["VIEW_CHANNEL"]
},
{
id: staff[0].ID,
allow: ["VIEW_CHANNEL"]
}

]
})

您不能再使用字符串设置通道的类型,您必须使用新的ChannelType枚举。你可以从discord.js库导入它,一旦你完成了导入,创建一个通道就会看起来像这样:

guild.channels.create({
name: "hello",
type: ChannelType.GuildText,
parent: cat[0].ID,
// your permission overwrites or other options here
});

还要确保所有参数都只在一个对象中传递,并且名称不是单独的参数。

最新更新