How to delete message if it’s not starting with specified word. Discord.js Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of How to delete message if it’s not starting with specified word. Discord.js without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I want to know how to make function that deletes message if it’s not starting with specified “word” not when message includes the word specified but when it’s starting with it (everything on specified channel with channel id), it’s very important for me and I can’t find any solution online. I’ve tried nothing because I don’t know how to make it.

Answer

Welcome, you can listen to the “message” event and check if the message starts with the string of your need. Example for you here:

const Discord = require("discord.js");

// Making our Discord Client
const client = new Discord.Client();

// Listens for the new message event
client.on("message", (message) => {
    // String of your need
    const str = "word";

    // Checking if string starts with your string of preference
    if (message.content.startsWith(str)) {
        // Deleting the message
        message.delete();
    }
});

I hope this helped you, you can read more about the event listeners here.

We are here to answer your question about How to delete message if it’s not starting with specified word. Discord.js - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji