Discord.js. I try to make a kick log but when i kick someone it isn't logging

Viewed 188

This is my code

bot.on("guildMemberRemove", async (member) => {
  const tlog = await member.guild.fetchAuditLogs({
    limit: 1,
    type: "MEMBER_KICK",
  });
  const klog = tlog.entries.first();
  const { executor, target } = klog;
  const rs = tlog.entries.first().reason;
  const emb = new Discord.MessageEmbed()
    .setTitle("Új KICK!") //New Kick Title
    .addField("Kickelt neve", target.user) //The kicked member name
    .addField("Kickelő neve", executor) //The member who kicked the other member
    .addField("Indok", rs) //Reason
    .setTimestamp()
    .setColor(15158332)
  addToLog(emb); 
})

addToLog Function

const channell = "792743591017316413"; //Channel id
function addToLog(message){
    const szoba = bot.channels.cache.get(channell); //szoba means room
    return szoba.send(message);
};

I looked more websites for the solution, but I completely copy the code and nothing happens.

2 Answers

If you take a look at the docs for TextChannel.send(). It returns a promise, you need to resolve this promise with either an await or .then().

I edited your code into:

    function addToLog(message, channel) {
      return channel.send(message);
    };

    bot.on("guildMemberRemove", async (member) => {
    const tlog = await member.guild.fetchAuditLogs({
      limit: 1,
      type: "MEMBER_KICK",
    });
   const klog = tlog.entries.first();
   const { executor, target } = klog;
   const rs = tlog.entries.first().reason;
   const channell = "Your channel ID"; //Channel id
   const szoba = bot.channels.cache.find(ch => ch.id === channell); 
   const emb = new Discord.MessageEmbed()
    .setTitle("Új KICK!") //New Kick Title
    .addField("Kickelt neve", target.user) //The kicked member name
    .addField("Kickelő neve", executor) //The member who kicked the other 
     member
    .addField("Indok", rs) //Reason
    .setTimestamp()
    .setColor(15158332)
   addToLog(emb, szoba); 
})

I used a second parameter channel, which in this case is your szoba. So you initialize the two constants channell and szoba outside of the function. Then you provide a message and your constant szoba (thats the channel you want your log been sent to). Inside of the function addToLog() you simply want the provided message sent to the provided channel (szoba).

Related