Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Quote:
When I was designing a bot for Discord, I got an error from a piece of code.I've tried everything, including debugs, but I can't find a solution.


client.on("message", msg => {
  db.fetch(`advertise_${msg.guild.id}`).then(i => {
    if (i == 'open') {
        const advertise = [".com", ".net", ".xyz", ".tk", ".pw", ".io", ".me", ".gg", "www.", "https", "http", ".gl", ".org", ".com.tr", ".biz", "net", ".rf.gd", ".az", ".party", "discord.gg"];
        if (reklam.some(word => msg.content.includes(word))) {
          try {
            if (!msg.member.hasPermission("BAN_MEMBERS")) {
                  msg.delete();
                    return msg.reply('Do Not Advertise!').then(msg => msg.delete(3000));


  msg.delete(3000);

            }
          } catch(err) {
            console.log(err);
          }
        }
    }
    else if (i == 'closed') {

    }
    if (!i) return;
  })
    });


What I have tried:

const advertise = [".com", ".net", ".xyz", ".tk", ".pw", ".io", ".me", ".gg", "www.", "https", "http", ".gl", ".org", ".com.tr", ".biz", "net", ".rf.gd", ".az", ".party", "discord.gg"];
Posted
Updated 23-May-21 1:38am

Given error is happening at:
"db.fetch('advertise_${msg.guild.id}').then(i => {"

Based on error, it is clear that you are getting no records for the code:
"db.fetch('advertise_${msg.guild.id}')"


You need to handle your code such that apply the filtering of then only if there were any records returned.
 
Share this answer
 
JavaScript
db.fetch(`advertise_${msg.guild.id}`).then(i => {

The message is telling you that the expression before .then yields a null reference, i.e. it returns nothing. So you need to find out why db.fetch(`advertise_${msg.guild.id}`) fails.

The same applies to
JavaScript
return msg.reply('Do Not Advertise!').then(msg => msg.delete(3000));

but you did not tell us which line raises the error.
 
Share this answer
 
v2
Comments
Alperen Türkeş 23-May-21 4:50am    
I'm so sorry, I forgot to mention the line of code where the error happened. I'm getting the error in this part: "db.fetch(`advertise_${msg.guild.id}`).then(i => {"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900