Managing messages

Replying to a message

client.on("messageCreate", async (message)=> {
    const member = await message.member;
    if (member.bot == true) return;
    if (message.content == "hi"){
       message.createMessage({ content: "hey there!" });
    }
});

Logging things to a specific channel

client.on("messageUpdate", async (message)=> {
    client.createMessage("channel id", { content: `A message has been updated (channel id: ${message.channelID})` });
});

Deleting bad words

client.on("messageCreate", async (message)=> {
    if (message.content.includes("fuck")) message.delete();
});

Editing messages

There's different ways to edit messages sent by the bot.

1. Storing new message.

client.on("messageCreate", async (message)=> {
   const member = await message.member;
   if (member.bot == true) return;
   if (message.content == "!ping"){
       let reply = await message.createMessage({ content: ".." });
       await reply.editMessage({ content: "pong!" });
   }
});

2. Using editLastMessage

client.on("messageCreate", async (message)=> {
   const member = await message.member;
   if (member.bot == true) return;
   if (message.content == "!ping"){
       await message.createMessage({ content: ".." });
       await message.editLastMessage({ content: "pong!" });
   }
});

Last updated