Is there a way to get the id of a channel by finding it using it's name?

If there isn't. Should this work instead?
const channel = message.guild.channels.find('name', 'yara-audit-log')
const channel = message.guild.channels.find('name', 'yara-audit-log')
13 Replies
d.js docs
d.js docs2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
monbrey
monbrey2y ago
That find syntax hasnt be correct since like..... v11 find(channel => channel.name === 'yara-audit-log')
PAdventures
PAdventures2y ago
const { ChannelType, PermissionsBitField, SlashCommandBuilder, EmbedBuilder } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('log')
.setDescription('Creates an audit log channel for Yara.'),
async execute(interaction){
const channel = interaction.guild.channels.ChannelTypefind(channel => channel.name === 'yara-audit-log')
if (channel) {
const channelExistsEmbed = new EmbedBuilder()
.setColor('Red')
.setTitle(`❌ | You already have a channel called \`yara-aduit-log\``)
.setDescription(`Either, delete the old channel and use this command again, OR don't use this command again.`)
interaction.reply({ embeds: [channelExistsEmbed], ephemeral: true })
} else {
guild.channels.create({
name: 'yara-audit-log',
type: ChannelType.GuildText,
permissionOverwrites: [
{
id: interaction.guild.id,
deny: [PermissionsBitField.Flags.ViewChannel],
},
{
id: interaction.user.id,
allow: [PermissionsBitField.Flags.ViewChannel],
},
],
});
const warningEmbed = new EmbedBuilder()
.setColor('Red')
.setTitle('⚠️ | You must configure the permissions of the audit-log yourself.')
interaction.reply({ embeds: [warningEmbed], ephemeral: true })
}
}
}
const { ChannelType, PermissionsBitField, SlashCommandBuilder, EmbedBuilder } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('log')
.setDescription('Creates an audit log channel for Yara.'),
async execute(interaction){
const channel = interaction.guild.channels.ChannelTypefind(channel => channel.name === 'yara-audit-log')
if (channel) {
const channelExistsEmbed = new EmbedBuilder()
.setColor('Red')
.setTitle(`❌ | You already have a channel called \`yara-aduit-log\``)
.setDescription(`Either, delete the old channel and use this command again, OR don't use this command again.`)
interaction.reply({ embeds: [channelExistsEmbed], ephemeral: true })
} else {
guild.channels.create({
name: 'yara-audit-log',
type: ChannelType.GuildText,
permissionOverwrites: [
{
id: interaction.guild.id,
deny: [PermissionsBitField.Flags.ViewChannel],
},
{
id: interaction.user.id,
allow: [PermissionsBitField.Flags.ViewChannel],
},
],
});
const warningEmbed = new EmbedBuilder()
.setColor('Red')
.setTitle('⚠️ | You must configure the permissions of the audit-log yourself.')
interaction.reply({ embeds: [warningEmbed], ephemeral: true })
}
}
}
error
Error: An error occured when executing log:
at Object.execute (D:\Yara Bot\Events\interactionCreate.js:12:27)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
node:events:498
throw er; // Unhandled 'error' event
^

TypeError: "" is not a function
at Object.execute (D:\Yara Bot\Events\interactionCreate.js:16:31)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:381:10)
at processTicksAndRejections (node:internal/process/task_queues:85:21)
[nodemon] app crashed - waiting for file changes before starting...
Error: An error occured when executing log:
at Object.execute (D:\Yara Bot\Events\interactionCreate.js:12:27)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
node:events:498
throw er; // Unhandled 'error' event
^

TypeError: "" is not a function
at Object.execute (D:\Yara Bot\Events\interactionCreate.js:16:31)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:381:10)
at processTicksAndRejections (node:internal/process/task_queues:85:21)
[nodemon] app crashed - waiting for file changes before starting...
^
monbrey
monbrey2y ago
interactionCreate.js:16:31 Its from there Not this file although maybe it is What is ChannelTypefind
PAdventures
PAdventures2y ago
i have no idea typo?
const { InteractionType, EmbedBuilder } = require('discord.js');
module.exports = {
name: 'interactionCreate',
async execute(interaction) {
if (!interaction.type === InteractionType.ApplicationCommand) return;
const commands = interaction.client.slash_commands.get(interaction.commandName);
if (!commands) return;

try {
await commands.execute(interaction);
} catch (error) {
console.error(new Error(`An error occured when executing ${interaction.commandName}: `, error));
const interactionErrorEmbed = new EmbedBuilder()
.setColor('#ce3636')
.setTitle('❌ | There was an error while executing this command.')
--> .setDescription(${error});
await interaction.reply({ embeds: [interactionErrorEmbed], ephemeral: true });
}
}
}
const { InteractionType, EmbedBuilder } = require('discord.js');
module.exports = {
name: 'interactionCreate',
async execute(interaction) {
if (!interaction.type === InteractionType.ApplicationCommand) return;
const commands = interaction.client.slash_commands.get(interaction.commandName);
if (!commands) return;

try {
await commands.execute(interaction);
} catch (error) {
console.error(new Error(`An error occured when executing ${interaction.commandName}: `, error));
const interactionErrorEmbed = new EmbedBuilder()
.setColor('#ce3636')
.setTitle('❌ | There was an error while executing this command.')
--> .setDescription(${error});
await interaction.reply({ embeds: [interactionErrorEmbed], ephemeral: true });
}
}
}
this is line 16 .setDescription(${error});
monbrey
monbrey2y ago
No This isn't interactionCreate.js Oh nvm I see now
PAdventures
PAdventures2y ago
it is
monbrey
monbrey2y ago
Yeah that's the error
PAdventures
PAdventures2y ago
how do i fix error not make an error?
monbrey
monbrey2y ago
Seems like you meant to use a template literal?
PAdventures
PAdventures2y ago
yes does the .setChannelOption covert the name of the channel into it;s id? so if i type #cheese in the option. and i use const cheese = interaction.options.getChannel('name') and i console.log(cheese). will it output #cheese or the id of #cheese? if it outputs #cheese can i do cheese.id to get the id? nvm i got it
monbrey
monbrey2y ago
It will output the whole channel object
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View