最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Why Discord.js API dont see message.channel.id? - Stack Overflow

programmeradmin7浏览0评论

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 mand 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_mands.forEach(function (element) {
        if (element.id == "club" && elementmands.includes(args[0])) {
            isClub = true;
        }
    });
    if (!isClub) {
        return false;
    }
    club_mands.forEach(function (element) {
        // element is parsed object from JSON: {"id":"join", "mands":"join,attach,invite..."}
        if (elementmands.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' }       

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 mand 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_mands.forEach(function (element) {
        if (element.id == "club" && element.mands.includes(args[0])) {
            isClub = true;
        }
    });
    if (!isClub) {
        return false;
    }
    club_mands.forEach(function (element) {
        // element is parsed object from JSON: {"id":"join", "mands":"join,attach,invite..."}
        if (element.mands.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' }       
Share Improve this question edited Jul 1, 2019 at 6:19 MD Ruhul Amin 4,5022 gold badges24 silver badges38 bronze badges asked Jun 30, 2019 at 23:28 Aspin TojpsAspin Tojps 351 gold badge4 silver badges10 bronze badges 2
  • 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 Commented Jul 1, 2019 at 5: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 Commented Jul 1, 2019 at 12:29
Add a ment  | 

1 Answer 1

Reset to default 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 pare the value of message.channel.id. For the difference between the two, check out this answer.

(message.channel.id === channel_dev && message.author.bot)
发布评论

评论列表(0)

  1. 暂无评论