Delete single message using tmi.js in Node.js

Greetings,

I’ve pored over the Twitch IRC tags and commands in the docs here, but I’m having a tough time cracking this. I have two questions:

  1. What is the syntax for getting a message’s ID in Twitch chat? Here’s what I’ve tried. For the moment I’m just outputting it to chat when I’m not streaming, for testing purposes:

    client.on(“chat”, (channel, user, message) => {
    #
    # OTHER STUFF HAPPENS HERE, TO TRAP FOR MY BOT’S COMMANDS
    #
    client.action(channel, “@” + user[“display-name”] + " " + message[“id”] + “, testing”);
    client.action(channel, “@” + user[“display-name”] + " " + message.id + “, testing”);
    }

    user[“display-name”] works as expected. Both message[“id”] and message.id return “undefined.”

  2. Once I do have the id, how do I delete the message?

Thanks!
DM

Sounds like you are using TMI.js?

You can console.log(message); to see what all the keys are in message.

As per the docs:

Edit: removed incorrect information

Hi Barry,

Thanks for the reply!

Actually, I tried message[“msg-id”] before I tried the others, and it also returned undefined. And message.msg-id causes the Node.js script to abort, as you have to use brackets and quotes when there is a hyphen involved.

I added console.log(message) and typed a test message into chat, but all that showed up in the log was the text of the message itself.

Any other suggestions would be most appreciated. :sunglasses:

Are you using TMI.js ?

I misread something it is id.

But it’s in the tags.

I’m not sure where TMI.js puts that if you are using tmi.js

BTW, the reason I didn’t include the msg-id tag in my OP is that it appears that it would only return a sort of status name rather than a discreet id of the specific message. Am I interpreting this correctly?

Rather than deleting you can edit posts, things in the thread are out of order…

To reiterate yes it’s id for the message unique ID, I hiccuped msg-id is the identifier to determine the type of USERNOTICE etc.

To confirm are you using TMI.js?

As this sounds like a library question, not a Twitch IRC question

Yeah, I deleted and reposted as a direct reply to you, and it went through right after you replied. And yes, it’s tmi.js. Thanks for the suggestion re library. I just joined the discord per the link here.

You don’t need to do that. Just reply to the thread. No need to directly reply.

I don’t use TMI.js as I roll my own module.

Looking at

It might be in the userstate payload. Where message is the text of the message.

So user['id'] from your OP may contain it.

Thanks for that suggestion as well. I’ll dig some more.

Yup! I tried adding a console.log(user.id) statement and then typing test messages into my chat. Each time I did, it returned a number like this: c85cc3bb-3635-5184-a728-5f7b081f2b92. So I’m thinking that this must be the actual ID of the message, as it changed with each message I typed.

Next step is to figure out how to delete said message. I did find this at line 177 of commands.js in the lib directory of tmi.js:

        // Delete a specific message on a channel

        deletemessage: function deletemessage(channel, messageUUID) {
            channel = _.channel(channel);
            // Send the command to the server and race the Promise against a delay..
            return this._sendCommand(this._getPromiseDelay(), channel, `/delete ${messageUUID}`, (resolve, reject) => {
                // Received _promiseDeletemessage event, resolve or reject..
                this.once("_promiseDeletemessage", (err) => {
                    if (!err) { resolve([channel]); }
                    else { reject(err); }
                });
            });
        },

I just need to get my syntax right for requiring commands.js in my bot in order to use this. I know that’s another library question, and I will ask it in the Discord. Posting it here anyway, just in case someone knows.

client.deletemessage("channel", "6a3b469b-f576-4b17-8700-fe24d36a2f73")
.then((data) => {
    // data returns [channel]
}).catch((err) => {
    //
});

Thanks!!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.