Please describe the problem you are having in as much detail as possible:
I am trying to send a message to a channel by ID but ChannelManager.fetch always returns null. When I pass the channel ID as number, or pass an invalid channel ID, I get a DiscordAPIError with the message: Unknown Channel so I'm guessing it's finding the channel.
Include a reproducible code sample here, if possible:
My own code:
const discordbot = require('discord.js');
const logChannel = 'channelId';
let bot = new discordbot.Client();
// [...]
bot.channels
.fetch(logChannel)
.then(channel => {
console.log('fetched channel: ', channel.name);
channel.send('', {
embed: {
author: {
name: 'Bot | Log'
},
title: tType, // "Info" / "Success" / "Warning" / "Error"
description: msg, // message is passed as argument
color: cColor, // 0x [HEX Value]
footer: `Bot Log vom ${tSd}.${tSm}.${tSy}` // timestamp
}
});
})
.catch(e => {
console.log('error posting log in channel\nError: ', e);
});
// [...]
bot.login('token');
My output:
error posting log in channel
Error: TypeError: Cannot read property 'name' of null
at /home/projects/i72-vf-discord-bot/bot.js:50:58
at processTicksAndRejections (internal/process/task_queues.js:93:5)
Further details:
The issue tracker shouldn't be used for reporting personal issues; such as receiving no Channel object back when trying to fetch it.
Second off, I was unable to reproduce this "bug", meaning that it's nothing to do with the library itself.
I've tested it on the latest version of discord.js — v12.0.2.
Snippet of my code:
this.client.channels.fetch("683245396058701824")
.then(channel => {
console.log((channel as GuildChannel).name); // test
});
However, I cannot pin-point as to why it would return null when fetching a Channel object from Discord. Technically, it should return (cases):
Missing Access — when the client isn't a part of the guild where the channel being fetched belongs to, but the channel does indeed exist.Unknown Channel — when Discord can't find that channel at all.Please ask for support in the Discord Server first before opening up an issue.
If necessary, you will be redirected from the server to open up an issue.
When you're there, could you please elaborate on what type of channel it is, and does the Client belong to the same guild that the channel [being fetched] is a part of.
can you try reproducing this bug while listening to the debug event?
bot.on('debug', console.log), it should log something like
Failed to find guild, or unknown type for channel ...
... being the channels ID and type, could you show this log
Hey, I am sorry but it wasn't the issue of the API but my own fault. I continued debugging in an older version (11.4.2 because that's the last one I had used before) and that gave me an unhandled promise rejection and after putting everything in try-catch/then-catch statements I figured that it was unable to login and I checked the token. I guess the fact that I had no response about that in version 12 isn't really intended though?
Sorry for posting it as a bug, I thought it was an issue with the API because I didn't really have information about what's going on
Edit on the debug event listener:
It tells me that it's about the token. Thanks for letting me know about that one :)
Another update:
I've had an email from Discord that my token has been resetted because my bot connected more than 1000 times within a short time period... Dammit