Paul
Paul
DIAdiscord.js - Imagine an app
Created by Paul on 6/26/2024 in #djs-questions
How to approach "replacing" (finding/deleting/reposting) a message in a designated channel?
The use case is this: people post an introduction in a public channel invoking my bot, the bot posts it into a read-only roster channel—but if the user already had an entry in the roster, the old entry is removed first. So each user only has at most one post in the roster channel, but can replace an old one with a new one. I had a version of this working some years ago using DJS 12, and it did it by fetching the last 100 messages in the roster channel and then searching through them, deleting the message if it found one, and then posting a new one. 100 is far enough back. Is there any more targeted way to accomplish this, short of maintaining an internal database/memory of message IDs that the bot has posted? I ask partly because my v12 code doesn't seem to be working anymore and I'm troubleshooting, but meanwhile wondering if I could just search a channel for something specific so I don't have to parse through all the messages myself. If my code continues not to work, I'll post what I'm doing, but meanwhile I'll keep playing with it to try to get it working in the current seemingly-inefficient way. Just wondering if there's a better approach. My quick searches in here suggests that the answer might be "no" but it doesn't seem like any answers I read were to questions about quite the use case I have.
9 replies