Checking whether a channel exists or has a duplicate - TypeError: fn.bind is not a function
Checking whether a channel exists or has a duplicate - TypeError: fn.bind is not a function
我正在尝试在 Discord.js
v12 中创建私人频道。我的代码如下:
const name = msg.author.tag;
const everyoneRole = msg.guild.roles.everyone;
if (msg.guild.channels.cache.find('name', name)) { //checks if there in an item in the channels collection that corresponds with the supplied parameters, returns a boolean
msg.reply(`You already have a channel`).catch(console.error);
return; //prevents the rest of the code from being executed
}
msg.guild.channels.create(msg.author.username, {type: 'category'})
.then(parent =>
Promise.all([
msg.guild.channels.create(name, {type: 'text', parent}).then(r => {
r.updateOverwrite(msg.author.id, { VIEW_CHANNEL: true });
r.updateOverwrite(everyoneRole, { VIEW_CHANNEL: false });
}),
msg.guild.channels.create(name, {type: 'voice', parent}).then(r => {
r.updateOverwrite(msg.author.id, { VIEW_CHANNEL: true });
r.updateOverwrite(everyoneRole, { VIEW_CHANNEL: false });
}),
])
)
const success = new Discord.MessageEmbed()
.setDescription(`Created, please see bottom of the server`)
await msg.channel.send(success).then(msg => msg.delete({timeout: 5000})).catch(O_o => {});
我正在检查频道是否存在。当我尝试使用名称 bot returns 查找频道时,我如下所示:
An error occurred while running the command: TypeError: fn.bind is not a function
You shouldn't ever receive an error like this.
我看过这些帖子:
TypeError: fn.bind is not a function
Way to check if a channel exists
但是大部分都没有解决我的问题。
我正在使用 Discord.js
v12
您的问题与您对 .find() 方法的使用有关。有了v12,方法变了(查看here)。
您需要更换:
msg.guild.channels.cache.find('name', name)
作者:
msg.guild.channels.cache.find(channel => channel.name === name);
我正在尝试在 Discord.js
v12 中创建私人频道。我的代码如下:
const name = msg.author.tag;
const everyoneRole = msg.guild.roles.everyone;
if (msg.guild.channels.cache.find('name', name)) { //checks if there in an item in the channels collection that corresponds with the supplied parameters, returns a boolean
msg.reply(`You already have a channel`).catch(console.error);
return; //prevents the rest of the code from being executed
}
msg.guild.channels.create(msg.author.username, {type: 'category'})
.then(parent =>
Promise.all([
msg.guild.channels.create(name, {type: 'text', parent}).then(r => {
r.updateOverwrite(msg.author.id, { VIEW_CHANNEL: true });
r.updateOverwrite(everyoneRole, { VIEW_CHANNEL: false });
}),
msg.guild.channels.create(name, {type: 'voice', parent}).then(r => {
r.updateOverwrite(msg.author.id, { VIEW_CHANNEL: true });
r.updateOverwrite(everyoneRole, { VIEW_CHANNEL: false });
}),
])
)
const success = new Discord.MessageEmbed()
.setDescription(`Created, please see bottom of the server`)
await msg.channel.send(success).then(msg => msg.delete({timeout: 5000})).catch(O_o => {});
我正在检查频道是否存在。当我尝试使用名称 bot returns 查找频道时,我如下所示:
An error occurred while running the command: TypeError: fn.bind is not a function You shouldn't ever receive an error like this.
我看过这些帖子:
TypeError: fn.bind is not a function
Way to check if a channel exists
但是大部分都没有解决我的问题。
我正在使用 Discord.js
v12
您的问题与您对 .find() 方法的使用有关。有了v12,方法变了(查看here)。
您需要更换:
msg.guild.channels.cache.find('name', name)
作者:
msg.guild.channels.cache.find(channel => channel.name === name);