Discord.js v14创建GuildAnnouncement频道遇DiscordAPIError[50035]求助
Discord.js v14创建公告频道报错问题解决
问题详情
在Replit中使用Discord.js v14.18.0开发频道结构机器人时,遇到以下问题:
- 创建
ChannelType.GuildAnnouncement(值为5)类型频道时,触发DiscordAPIError[50035],提示Value must be one of {0, 2, 4, 6, 13, 14, 15, 16} - 调用
channel.setType(ChannelType.GuildAnnouncement)将文本频道转为公告频道时,报错type[BASE_TYPE_CHOICES]: Value must be one of (0,) ChannelType.GuildText类型频道可正常创建
相关代码:
const channelList = [ { name: "general", type: ChannelType.GuildText }, { name: "next-session", type: ChannelType.GuildAnnouncement, edit: [ [{ SendMessages: null }, role.id], [{ SendMessages: true, ViewChannel: true }, process.env["CLIENT_ID"]], ], }]; for (const channelData of channelList) { const channel = await interaction.guild.channels.create({ name: channelData.name, type: channelData.type, parent: category.id, }); if (channelData.edit) { for (const [id, permissions] of channelData.edit) { await channel.permissionOverwrites.edit( permissions, id, ); } } if (channelData.delete) { for (const id of channelData.delete) { await channel.permissionOverwrites.delete(id); } }
原因及解决方法
1. 服务器社区功能未开启
公告频道的创建和类型转换依赖服务器的社区功能,未开启时Discord API会直接拒绝请求。
- 操作步骤:
- 打开目标服务器的Discord设置
- 进入「社区」选项卡,按引导完成社区配置(需设置规则频道、开启审核日志等)
- 配置完成后重试创建或转换频道
2. 权限覆写参数顺序错误
代码中permissionOverwrites.edit的参数顺序颠倒,正确顺序应为目标ID在前,权限对象在后:
// 修正前 await channel.permissionOverwrites.edit(permissions, id); // 修正后 await channel.permissionOverwrites.edit(id, permissions);
该错误虽不直接导致频道类型报错,但会引发权限配置失败,需同步修正。
3. 确认API与库版本兼容性
确保Discord.js版本与Discord API版本同步,可尝试更新到最新稳定版:
npm install discord.js@latest
4. 频道类型转换限制
未开启社区的服务器中,普通文本频道仅允许保持原类型,无法转换为公告频道。必须先开启社区功能,才能执行类型转换操作。
内容的提问来源于stack exchange,提问作者ercanon
相关产品推荐
相关产品推荐

