Doesn't fetch the channel, why?

const channel = client.channels.fetch("1198299044582281216", { force: true });
console.log(channel.name);
const channel = client.channels.fetch("1198299044582281216", { force: true });
console.log(channel.name);
12 Replies
d.js toolkit
d.js toolkit10mo 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!
probablyraging
probablyraging10mo ago
You need to await the promise returned when fetching
Tissemyren
TissemyrenOP10mo ago
then it just sets channel to null
probablyraging
probablyraging10mo ago
Show me how you're doing it
Tissemyren
TissemyrenOP10mo ago
const channel = await client.channels.fetch("1198299044582281216", { force: true });
console.log(channel.name);
const channel = await client.channels.fetch("1198299044582281216", { force: true });
console.log(channel.name);
probablyraging
probablyraging10mo ago
Show the full code where you're doing this
Tissemyren
TissemyrenOP10mo ago
const { EmbedBuilder, WebhookClient } = require("discord.js");

module.exports = async (client) => {
console.log("Loaded: Message Logger");

try {
const webhook = new WebhookClient({ id: '', token: '' });
const embed = new EmbedBuilder()
const channel = await client.channels.fetch("1198299044582281216", { force: true });
console.log(channel.name);

client.on("messageDelete", function(message) {
if (message.author.bot) return;


})

client.on("messageUpdate", function(oldMessage, message) {
if (message.author.bot) return;


})
} catch(error) {
console.error(error);
}
};
const { EmbedBuilder, WebhookClient } = require("discord.js");

module.exports = async (client) => {
console.log("Loaded: Message Logger");

try {
const webhook = new WebhookClient({ id: '', token: '' });
const embed = new EmbedBuilder()
const channel = await client.channels.fetch("1198299044582281216", { force: true });
console.log(channel.name);

client.on("messageDelete", function(message) {
if (message.author.bot) return;


})

client.on("messageUpdate", function(oldMessage, message) {
if (message.author.bot) return;


})
} catch(error) {
console.error(error);
}
};
probablyraging
probablyraging10mo ago
Do it in an event once the bot has connected and is in a ready state
d.js docs
d.js docs10mo ago
:event: (event) Client#ready Emitted when the client becomes ready to start working.
probablyraging
probablyraging10mo ago
And also make sure you reset your token now
Tissemyren
TissemyrenOP10mo ago
👍🏼
ahmood
ahmood10mo ago
You also don't need to force fetch a channel since channels are cached by default (except threads and dm channels)
Want results from more Discord servers?
Add your server