Why channel.type is not working for me without any errors

client.on("messageCreate", async (message) => {
if (message.channel.type === "DM") {
console.log("Tedt");
message.author.send("You are DMing me now!");
}
});
client.on("messageCreate", async (message) => {
if (message.channel.type === "DM") {
console.log("Tedt");
message.author.send("You are DMing me now!");
}
});
31 Replies
d.js toolkit
d.js toolkit2y 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.
Idris
Idris2y ago
.type returns a number not a string use message.channel.isDMBased()
d.js docs
d.js docs2y ago
Tag suggestion for @pooyaneftekhari: To receive direct message events on "messageCreate" with your bot, you will need: • The DirectMessages gateway intent • The Channel partial setting
Pooyan
PooyanOP2y ago
client.on("messageCreate", async (message) => {
if (message.channel.isDMBased()) {
console.log("Tedt");
message.author.send("You are DMing me now!");
}
});
client.on("messageCreate", async (message) => {
if (message.channel.isDMBased()) {
console.log("Tedt");
message.author.send("You are DMing me now!");
}
});
This doesn't work as well
const client = new Discord.Client(
{ intents: 32767 },
{ partials: ["MESSAGE", "CHANNEL", "REACTION"] }
);
const client = new Discord.Client(
{ intents: 32767 },
{ partials: ["MESSAGE", "CHANNEL", "REACTION"] }
);
Idris
Idris2y ago
I mean follow the guide I sent
Pooyan
PooyanOP2y ago
wdym
Idris
Idris2y ago
^ there all links
Pooyan
PooyanOP2y ago
what are the numbers it returns
Pooyan
PooyanOP2y ago
This doesn't work too!
client.on("messageCreate", async (message) => {
if (message.channel.type === 1) {
console.log("Tedt");
message.author.send("You are DMing me now!");
}
});
client.on("messageCreate", async (message) => {
if (message.channel.type === 1) {
console.log("Tedt");
message.author.send("You are DMing me now!");
}
});
Idris
Idris2y ago
will you read the guide or not?
Pooyan
PooyanOP2y ago
It's filtered for me I'm forbidden*
Idris
Idris2y ago
- const client = new Discord.Client({ intents: 32767 }, { partials: ["MESSAGE", "CHANNEL", "REACTION"] });
+ const client = new Discord.Client({ intents: 32767, partials: [Partials.Message, Partials.Channel, Partials.Reaction] });
- const client = new Discord.Client({ intents: 32767 }, { partials: ["MESSAGE", "CHANNEL", "REACTION"] });
+ const client = new Discord.Client({ intents: 32767, partials: [Partials.Message, Partials.Channel, Partials.Reaction] });
Idris
Idris2y ago
also 32767 isn't all intents
d.js docs
d.js docs2y ago
We highly recommend only specifying the intents you actually need. • Note, that 98303, 32767 or whatever other magic number you read that represents "all intents", gets outdated as soon as new intents are introduced. • The number will always represent the same set of intents, and will not include new ones. There is no magic "all intents" bit.
Pooyan
PooyanOP2y ago
weird
const client = new Discord.Client(
{ intents: 32767 },
{ partials: [Partials.Message, Partials.Channel, Partials.Reaction] }
);
const client = new Discord.Client(
{ intents: 32767 },
{ partials: [Partials.Message, Partials.Channel, Partials.Reaction] }
);
Idris
Idris2y ago
no
Pooyan
PooyanOP2y ago
This returns error
Idris
Idris2y ago
look at what I sent
Pooyan
PooyanOP2y ago
const { Partials } = require('discord.js');
Idris
Idris2y ago
why are you putting multiple objects?
Pooyan
PooyanOP2y ago
This bot is for testing anything that's why
Idris
Idris2y ago
const client = new Discord.Client({
intents: 32767,
partials: ["MESSAGE", "CHANNEL", "REACTION"]
});
const client = new Discord.Client({
intents: 32767,
partials: ["MESSAGE", "CHANNEL", "REACTION"]
});
that's how you set options
Pooyan
PooyanOP2y ago
partials: [Partials.Message, Partials.Channel, Partials.Reaction]
^

TypeError: Cannot read properties of undefined (reading 'Message')
partials: [Partials.Message, Partials.Channel, Partials.Reaction]
^

TypeError: Cannot read properties of undefined (reading 'Message')
Idris
Idris2y ago
ohhh I'm dumb sorry
Pooyan
PooyanOP2y ago
I'm using [email protected] is that ok?
Idris
Idris2y ago
didn't saw in you were on v13
Pooyan
PooyanOP2y ago
Ariya
Idris
Idris2y ago
edited ^ message.channel.type === "DM" was fine too
Pooyan
PooyanOP2y ago
Thanks so why it didn't work at first time? Was is because I defined Client like that?
{ intents }
{ partials}
{ intents }
{ partials}
Idris
Idris2y ago
yep
Want results from more Discord servers?
Add your server