![](/img/trans.png)
[英]Check if bot has permissions in a specific channel discord.js v14
[英]How to create a private channel only the user and the bot can see in Discord.js v14?
我嘗試在 Discord.js v14 中創建私人頻道,但我的代碼返回錯誤。
這是我的代碼的相關部分:
else if (interaction.customId === 'donatid') {
if(interaction.values[0] == '01'){
const everyoneRole = interaction.guild.roles.everyone;
const name = interaction.user.tag;
interaction.guild.channels.create(name, 'text') // i think problem over here
.then(r => {
r.overwritePermissions(interaction.author.id, { VIEW_CHANNEL: true });
r.overwritePermissions(client.id, { VIEW_CHANNEL: true });
r.overwritePermissions(everyoneRole, { VIEW_CHANNEL: false });
})
.catch(console.error);
}
};
和錯誤:
DiscordAPIError\[50035\]: Invalid Form Body
您的代碼中有幾個錯誤。 在 v14 中, create()
接受options
object 並且"text"
不再是有效類型。 您應該導入ChannelType
枚舉並為此使用ChannelType.GuildText
。
沒有interaction.author
。 有一個interaction.user
或interaction.member
,所以如果你想使用作者的 ID,你可以使用它們。
也沒有client.id
。 不過,您可以使用client.user.id
獲取機器人的 ID。
此外,您可以在create
方法中添加權限作為選項,這樣您就不必then
使用它了。 請參閱下面的工作代碼:
const { ChannelType, PermissionFlagsBits } = require('discord.js');
//...
interaction.guild.channels.create({
name: interaction.user.tag,
type: ChannelType.GuildText,
permissionOverwrites: [
{
id: interaction.guild.roles.everyone,
deny: [PermissionFlagsBits.ViewChannel],
},
{
id: interaction.user.id,
allow: [PermissionFlagsBits.ViewChannel],
},
{
id: client.user.id,
allow: [PermissionFlagsBits.ViewChannel],
},
],
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.