Delete Message from User in DM

Is it possible, to delete all Messages from the Bot and User in DMs
32 Replies
d.js toolkit
d.js toolkit•9mo 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!
chewie
chewie•9mo ago
The bot can only delete the bots messages.
Shrewd 💫
Shrewd 💫•9mo ago
How would you approach it, to remove all messages sent from the bot in someone's direct messages? I've got no use for it right now, however, it is worth knowing for future reference!
chewie
chewie•9mo ago
by doing it the spammy way: fetch, iterate, delete
Shrewd 💫
Shrewd 💫•9mo ago
How do you fetch someone's dms again? Also, are we to expect the message after 14 days saying we can't delete it?
chewie
chewie•9mo ago
<DMChannel>#messages#fetch - as usual <User>#createDM for the channel And no, thats just for bulkdelete
Shrewd 💫
Shrewd 💫•9mo ago
Well. I guess I have learned two things. Didn't know that the day limit applies only to the BulkDelete. Thanks for explaining
Rahmat
Rahmat•4mo ago
Hi, can you please explain how we can do it?
client.users.fetch(_userId).then((user) => {
const messages = user.dmChannel.messages;
});
client.users.fetch(_userId).then((user) => {
const messages = user.dmChannel.messages;
});
I am new to discord.js. I have enabled all Intents to see if that's the problem. But .dmChannel always null for me.
treble/luna
treble/luna•4mo ago
you need to call createDM first.
d.js docs
d.js docs•4mo ago
:method: User#createDM() discord.js@14.19.3 Creates a DM channel between the client and the user.
Rahmat
Rahmat•4mo ago
But I am sending user dms through user.send() and have a lot of messages from bot in dm. It means sending dms through user.send() is wrong approac? Detailed code to send dm:
client.users.fetch(_userId).then((user) => {
user.send(_message);
});
client.users.fetch(_userId).then((user) => {
user.send(_message);
});
treble/luna
treble/luna•4mo ago
that has nothing to do with this though the dmchannel isnt cached by default so you have to call createDM
Rahmat
Rahmat•4mo ago
OK, so createDM() worked for. What I have learnt is that if we use user.send(_message) directly without calling createDM(), it will not cache/save the messages sent to user but user will receive the dms from bot. By calling createDM() first on user then using send() on the returned reference will cache the messages to be used in future.
const user = await client.users.fetch(_userId);
const dm = await user.createDM(); // user.send(_message) will send dm to user but will not save the messages for future use.
await dm.send(_message);
const user = await client.users.fetch(_userId);
const dm = await user.createDM(); // user.send(_message) will send dm to user but will not save the messages for future use.
await dm.send(_message);
Don't know why, but it looks to me that we have to call createDM() separately.
d.js docs
d.js docs•4mo ago
:method: UserManager#send() discord.js@14.19.3 Sends a message to a user.
Rahmat
Rahmat•4mo ago
Are you referring to solution something like this: https://stackoverflow.com/a/61029038/8823023 client.users.cache.get('id').send('Blabla') Thanks for it. Man, I am working for about 8+ years in TypeScript dealt, many libraries. But complexity of discort.js is on another level. Many thanks for the direction though. Yes, of course By the way, if some small examples added to the documentation, it will be way much easier, like: https://angular.dev/api/common/DecimalPipe
Amgelo
Amgelo•4mo ago
you might be referring to the guide? https://discordjs.guide
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
Rahmat
Rahmat•4mo ago
Nope, to the documentation it self.
Unknown User
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
Rahmat
Rahmat•4mo ago
Of course, not everything. But somethings should.
Unknown User
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
Rahmat
Rahmat•4mo ago
Like you can see, I have referred a small example from angular docs (https://angular.dev/api/common/DecimalPipe). They have added very few examples in the docs. If you go to the link and scroll to the references to the left of that page, you will find out almost many references don't have examples. But some important references have examples and helps a lot.
Unknown User
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
d.js docs
d.js docs•4mo ago
:method: GuildMemberManager#fetch() discord.js@14.19.3 Fetches member(s) from a guild.
// Fetch all members from a guild
guild.members.fetch()
.then(console.log)
.catch(console.error);
// Fetch all members from a guild
guild.members.fetch()
.then(console.log)
.catch(console.error);
Rahmat
Rahmat•4mo ago
Yes, very much like that. Maybe I haven't got any from doc by luck. I am very new to discord.js to point out anything. Surely, will if needed in future. To be specific, if I see myself new to discord api and what I struggled a lot, is the intents. Intents were very confusing to be understand why they are here. Well that's not about the discord.js but about the developer portal itself. If new person go to "Installation", "OAuth2" and "Bot" pages on the discord application page for a specific application, he can't distinguish between these 3 and will question why these 3 pages are there, not one. For the discord.js docs somehow I visited the only pages the examples were not there, I think those are good. But I want to point out that the guide started good. Like we even pointed out how to add linter and how to secure tokens using .env. But then suddenly in "creating your bot" in "command handling" we used different files for different commands and exported using module.exports. After that used node's file system to fetch files and access code within, this adds difficulty in learning the basics of slash commands (when I read those pages I thought it's something complex but after googling realized it's easier than expected). What I think, using file system and module.exports adds complexity/difficulty in learning at that point. Though, it's important to point out that the code will become pain if not managed through multiple files correctly, this could be told to the user in later parts of the guide.
treble/luna
treble/luna•4mo ago
The user is required to have a solid understanding of the basics of javascript before starting, this is also reflected in #rules 3. This includes working with the file system
Rahmat
Rahmat•4mo ago
Well, I am at ok to good level in file system and I know how they work, I pointed out to the are in guide about slash commands.
Amgelo
Amgelo•4mo ago
tbf even the basics of file handling are taught in the guide but yeah it is expected that users should use the library having that knowledge already
Rahmat
Rahmat•4mo ago
That's totally depend on the user. If they are programmers (as I expect mostly they are) we don't need to tell them how to manage code complexity. If they are new people and normal users with little to no programming experience then we should tell them about how to manage the code complexity/refactoring but then module.exports, node's file system will torture these kind of new comers
Unknown User
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
treble/luna
treble/luna•4mo ago
thats what we're trying to tell you, djs isnt meant for newcomers, they should have a solid understanding of javascript the guide is meant to guide people its not meant to learn the basics of javascript, that is not our job
Rahmat
Rahmat•4mo ago
Sure, I pointed out the difficulties I found some of them as asked. We can close the topic.
T̶h̶e̶ ̶O̶G̶x̶
Nahh... rather that simplifies my workflow massively... It lets you even customise how you want each command to be executed, for example cool downs, but still making sure everything converges to one loop. Very efficient. It's confusing for a start but once you start using it, you'd see how much better your refactoring would look like. The honest truth is: Discord.js feels difficult at first. The official guides are organized, but they don't really teach — they mostly turn you into a code copier. But once you do a bit more digging and understand how things work, you realize it’s actually very straightforward. In fact, the circular nature of the API is soooo solid — it keeps everything interconnected in a way that makes the library powerful once you understand the flow. But for the new guides, there's alot of improvements, they now use gifs and images to illustrate what is actually happening. Well that's true too.

Did you find this page helpful?