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

javascript - How do I fix "Declaration or statement expected. ts(1128)" in Discord.js? - Stack Overflow

programmeradmin1浏览0评论

I just started coding a Discord bot, and I'm having a problem with coding with Giphy API. I don't know if the entire code is wrong, but anyways I'm confused with it. How do I fix the problem?

The first If-Then statement doesn't give out any errors, but the second one in the code does give out an error.

I'm using Visual Studio Code to code, and Discord.js as the Node.js module.

client.on('message', message =>{
    //console.log(message.content);

    if(message.content.startsWith(`${prefix}`)) {
    message.channel.send("oh yeah it's the prefix of the bot")
    }

    if(message.content.startsWith(`${prefix}gif`)) {
    giphy.trending("gifs", {})
        .then((response) => {
            var totalResponses = response.data.length;
            var responseIndex = Math.floor((Math.random() * 10) +1) % totalResponses;
            var responseFinal = response.data[responseIndex]

            message.channel.send("There you go!", {
                files: [responseFinal.images.fixed_height.url]
            })
            file
    })
})

The error:

Declaration or statement expected ts(1128)

I just started coding a Discord bot, and I'm having a problem with coding with Giphy API. I don't know if the entire code is wrong, but anyways I'm confused with it. How do I fix the problem?

The first If-Then statement doesn't give out any errors, but the second one in the code does give out an error.

I'm using Visual Studio Code to code, and Discord.js as the Node.js module.

client.on('message', message =>{
    //console.log(message.content);

    if(message.content.startsWith(`${prefix}`)) {
    message.channel.send("oh yeah it's the prefix of the bot")
    }

    if(message.content.startsWith(`${prefix}gif`)) {
    giphy.trending("gifs", {})
        .then((response) => {
            var totalResponses = response.data.length;
            var responseIndex = Math.floor((Math.random() * 10) +1) % totalResponses;
            var responseFinal = response.data[responseIndex]

            message.channel.send("There you go!", {
                files: [responseFinal.images.fixed_height.url]
            })
            file
    })
})

The error:

Declaration or statement expected ts(1128)

Share Improve this question edited Aug 9, 2019 at 22:48 Erik Russell 8811 gold badge10 silver badges19 bronze badges asked Aug 9, 2019 at 12:28 RaymondRaymond 811 gold badge2 silver badges18 bronze badges 3
  • Well, surely the error message points you to a line... What do you expect file is doing all by itself? – tehhowch Commented Aug 9, 2019 at 12:34
  • Also, you are missing the closing bracket of the if(message.content.startsWith(${prefix}gif)) { – DedaDev Commented Aug 9, 2019 at 17:25
  • it's the second end "}" – Raymond Commented Aug 9, 2019 at 18:45
Add a ment  | 

1 Answer 1

Reset to default 3

You are missing a closing curly bracket -- this is your exact code, but fixed.

client.on('message', message => {
    //console.log(message.content);

    if (message.content.startsWith(`${prefix}`)) {
        message.channel.send("oh yeah it's the prefix of the bot")
    }

    if (message.content.startsWith(`${prefix}gif`)) {
        giphy.trending("gifs", {})
            .then((response) => {
                var totalResponses = response.data.length;
                var responseIndex = Math.floor((Math.random() * 10) + 1) % totalResponses;
                var responseFinal = response.data[responseIndex]

                message.channel.send("There you go!", {
                    files: [responseFinal.images.fixed_height.url]
                })
                file
            })
    }
})
发布评论

评论列表(0)

  1. 暂无评论