Is there a quick and easy way to get a channels name by id?

this code drops an error so ig im doing it wrong
client.channels
.fetch(message.channel)
.then((ch) => console.log('channel name is: ' + ch.name))
.catch(console.error);
client.channels
.fetch(message.channel)
.then((ch) => console.log('channel name is: ' + ch.name))
.catch(console.error);
DiscordAPIError[50035]: Invalid Form Body
channel_id[NUMBER_TYPE_COERCE]: Value "<" is not snowflake.
at handleErrors (/home/j44/Downloads/themer/tut/node_modules/@discordjs/rest/dist/index.js:687:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.runRequest (/home/j44/Downloads/themer/tut/node_modules/@discordjs/rest/dist/index.js:1072:23)
at async SequentialHandler.queueRequest (/home/j44/Downloads/themer/tut/node_modules/@discordjs/rest/dist/index.js:913:14)
at async _REST.request (/home/j44/Downloads/themer/tut/node_modules/@discordjs/rest/dist/index.js:1218:22)
at async ChannelManager.fetch (/home/j44/Downloads/themer/tut/node_modules/discord.js/src/managers/ChannelManager.js:123:18) {
requestBody: { files: undefined, json: undefined },
rawError: {
message: 'Invalid Form Body',
code: 50035,
errors: { channel_id: [Object] }
},
DiscordAPIError[50035]: Invalid Form Body
channel_id[NUMBER_TYPE_COERCE]: Value "<" is not snowflake.
at handleErrors (/home/j44/Downloads/themer/tut/node_modules/@discordjs/rest/dist/index.js:687:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.runRequest (/home/j44/Downloads/themer/tut/node_modules/@discordjs/rest/dist/index.js:1072:23)
at async SequentialHandler.queueRequest (/home/j44/Downloads/themer/tut/node_modules/@discordjs/rest/dist/index.js:913:14)
at async _REST.request (/home/j44/Downloads/themer/tut/node_modules/@discordjs/rest/dist/index.js:1218:22)
at async ChannelManager.fetch (/home/j44/Downloads/themer/tut/node_modules/discord.js/src/managers/ChannelManager.js:123:18) {
requestBody: { files: undefined, json: undefined },
rawError: {
message: 'Invalid Form Body',
code: 50035,
errors: { channel_id: [Object] }
},
10 Replies
d.js toolkit
d.js toolkit14mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by staff
duck
duck14mo ago
well message.channel is already the channel, not an id
Jannik44
Jannik44OP14mo ago
when i log it its an id
duck
duck14mo ago
but you can get a channel by id with <Client>.channels.cache.get(<id>) it definitely shouldn't be and your error suggests otherwise
Jannik44
Jannik44OP14mo ago
No description
No description
Jannik44
Jannik44OP14mo ago
hmm weird
duck
duck14mo ago
well in this case you appear to be stringifying the channel object it is weird that the first log isn't a channel mention but in general your error behaves as expected for the expected value of <Message>.channel
Jannik44
Jannik44OP14mo ago
so this will return an actual channel/thread name instead of a mention right?
duck
duck14mo ago
no, the channel cache contains Channel objects you can access <GuildBasedChannel>.name for non-dm channels
Jannik44
Jannik44OP14mo ago
oh, its actually that easy 🙂 nice finally its working
Want results from more Discord servers?
Add your server