1

I have just created a simple bot with that code:

client.on('message', async message => {
    if (!message.author.bot) {
        if (!getClub(message) && (message.channel.id == channel_bot || message.channel.type != "dm")) { // 
            getRadio(message);
        }
    } else if (message.channel.id = channel_dev && message.author.bot) {
        getDevCommands(message);
    }
});

and I check bot command with

function getClub(msg) {
    const args = msg.content.slice(msg.content.includes(config.prefix) ? config.prefix.length : 0).trim().split(/ +/g);

    let isClub = false;
    club_commands.forEach(function (element) {
        if (element.id == "club" && element.commands.includes(args[0])) {
            isClub = true;
        }
    });
    if (!isClub) {
        return false;
    }
    club_commands.forEach(function (element) {
        // element is parsed object from JSON: {"id":"join", "commands":"join,attach,invite..."}
        if (element.commands.includes(args[1])) {
            switch (element.id) {
                case "stats":
                    clubStats(msg);
                    return true;
                case "join":
                    clubParticipation(msg, 1);
                    return true;
                case "leave":
                    clubParticipation(msg, 0);
                    return true;
                default:
                    // do nothing
                    break;
            }
        }
    });
    return false;
}

So in clubPartisipation() im getting in msg.channel.id - actual channel id but only "true" for the all next messages

function clubParticipation(msg, status) {
    const args = msg.content.trim().split(/ +/g).splice(2, 2).join("");
    if (args.length <= 3) {
        msg.channel.send("test0");
    } else {
        let member = guild.members.get(msg.author.id);
        if (status == "1") {
            msg.channel.send("test1").catch(console.log);
        } else {
            msg.channel.send("test3").catch(console.log);
        }
        getHTTPResponce(config.server_url + 'add/club/participation?channel_id=' + msg.channel.id + '&status=' + status + '&user_id=' + member.id + '&club_id=' + Base64.encode(Base64.encode(args)) + '&token=' + config.server_token, msg)
            .catch(console.log);
    }
}

Error code is

{ DiscordAPIError: Invalid Form Body                                                                                       
channel_id: Value "true" is not snowflake.                                                                                 
    at item.request.gen.end (/root/curatortojps/node_modules/discord.js/src/client/rest/RequestHandlers/Sequential.js:85:15
)                                                                                                                          
    at then (/root/curatortojps/node_modules/snekfetch/src/index.js:215:21)                                                
    at <anonymous>                                                                                                         
    at process._tickCallback (internal/process/next_tick.js:189:7)                                                         
  name: 'DiscordAPIError',                                                                                                 
  message: 'Invalid Form Body\nchannel_id: Value "true" is not snowflake.',                                                
  path: '/api/v7/channels/true/messages',                                                                                  
  code: 50035,                                                                                                             
  method: 'POST' }       
MD Ruhul Amin
  • 4,386
  • 1
  • 22
  • 37
Aspin Tojps
  • 35
  • 1
  • 3
  • 10
  • Do you mind adding context to you question? Do no paste your entire code, paste the part where the problem is. If something else is needed people will tell you. But here we have 50 lines of code to read and try to understand where is the problem. Also format your error with code next time (I can't edit it because you didn't write enough context and the question is only code) – JackRed Jul 01 '19 at 05:31
  • Look at JackRed. he cant find a problem. if u dont know i can tell u this error type dont givea a link to problem code – Aspin Tojps Jul 01 '19 at 12:29

1 Answers1

4

In your first block of code, you have:

(message.channel.id = channel_dev && message.author.bot)

= is an assignment operator. This means that you're setting message.channel.id to the value of channel_dev && message.author.bot, a boolean (true or false).


You should use an equality operator like == or === to compare the value of message.channel.id. For the difference between the two, check out this answer.

(message.channel.id === channel_dev && message.author.bot)
slothiful
  • 5,548
  • 3
  • 12
  • 36
JackRed
  • 1,188
  • 2
  • 12
  • 28