How can i use fetch message using DM?

How can i use fetch message using DM?
19 Replies
d.js toolkit
d.js toolkit9mo 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!
d.js docs
d.js docs9mo ago
:property: DMChannel#messages A manager of the messages belonging to this channel
ABDULLAH
ABDULLAHOP9mo ago
Code? Just DM no, I have problem fetch message id for edit message in DM?
d.js docs
d.js docs9mo ago
:method: MessageManager#edit() Edits a message, even if it's not cached.
ABDULLAH
ABDULLAHOP9mo ago
I have problem fetch message id in DM? Direct Message
NyR
NyR9mo ago
@ABDULLAH please show your code, how are you having the problem, any errors you might be getting?
ABDULLAH
ABDULLAHOP9mo ago
I think
interaction.member.messages.fetch()?
interaction.member.messages.fetch()?
NyR
NyR9mo ago
There's no message property in member (not that there's member property for DM channels, but that's besides the point)
ABDULLAH
ABDULLAHOP9mo ago
member.messages.fetch() does not exist?
NyR
NyR9mo ago
No, <Channel>.messages.fetch() is You were told here how to fetch dm messages here
ABDULLAH
ABDULLAHOP9mo ago
Where fetch message DM in discord.js?
NyR
NyR9mo ago
Can you please show the code where you 'try' to fetch the message, and not just a part of the code, full code
ABDULLAH
ABDULLAHOP9mo ago
await message.dmchannel.messages.fetch();
await message.dmchannel.messages.fetch();
I think right?
NyR
NyR9mo ago
Bro i said show the full code and not just the part of it But if the message is from the dm channel then
message.channel.messages.fetch()
message.channel.messages.fetch()
ABDULLAH
ABDULLAHOP9mo ago
I already
NyR
NyR9mo ago
^ please show your full code, what errors you get. Otherwise I can't help you! I can't magically know stuff
ABDULLAH
ABDULLAHOP9mo ago
const discord = require("discord.js");
const database = require("../../utils/database");
const db = new database();
const tempApplyDB = require("../database/models/tempApply");

module.exports = class tempApply {
constructor(client, sequelize) {
this.client = client;
this.sequelize = sequelize;
}
async run() {
const tempApply = tempApplyDB(this.sequelize);
setInterval(async () => {
const guildd = this.client.guilds.cache.get("1091806599410110476");

const arrayTempApply = await db.find(tempApply, {
guildID: guildd.id,
});

for (const applyDoc of arrayTempApply) {
if (Number(applyDoc.time) <= Date.now()) {
const guild = this.client.guilds.cache.get("1091806599410110476");
const members = await guild.members.fetch();
const member = members.get(applyDoc.memberID);
if (!member) {
await db.deleteOne(tempApply, {
guildID: guild.id,
memberID; applyDoc.memberID,
});
return;
}
const message = await member.messages.fetch(applyDoc.messageID);

message.edit({
content: "You took too long!",
embeds: [],
components: [],
}).catch(() => {});

await db.deleteOne(tempApply, {
guildID: guild.id,
memberID: applyDoc.memberID,
});

continue;
}
}
}, 60000);
}
};
const discord = require("discord.js");
const database = require("../../utils/database");
const db = new database();
const tempApplyDB = require("../database/models/tempApply");

module.exports = class tempApply {
constructor(client, sequelize) {
this.client = client;
this.sequelize = sequelize;
}
async run() {
const tempApply = tempApplyDB(this.sequelize);
setInterval(async () => {
const guildd = this.client.guilds.cache.get("1091806599410110476");

const arrayTempApply = await db.find(tempApply, {
guildID: guildd.id,
});

for (const applyDoc of arrayTempApply) {
if (Number(applyDoc.time) <= Date.now()) {
const guild = this.client.guilds.cache.get("1091806599410110476");
const members = await guild.members.fetch();
const member = members.get(applyDoc.memberID);
if (!member) {
await db.deleteOne(tempApply, {
guildID: guild.id,
memberID; applyDoc.memberID,
});
return;
}
const message = await member.messages.fetch(applyDoc.messageID);

message.edit({
content: "You took too long!",
embeds: [],
components: [],
}).catch(() => {});

await db.deleteOne(tempApply, {
guildID: guild.id,
memberID: applyDoc.memberID,
});

continue;
}
}
}, 60000);
}
};
ahmood
ahmood9mo ago
fetch the dm channel then fetch the message from that dm channel
d.js docs
d.js docs9mo ago
:method: DMChannel#fetch() Fetch this DMChannel. :method: User#createDM() Creates a DM channel between the client and the user.
Want results from more Discord servers?
Add your server