javascript - 如何修复 Discord.js 中的 "Declaration or statement expected. ts(1128)"?

标签 javascript node.js discord.js giphy-api

我刚刚开始编写 Discord 机器人,并且在使用 Giphy API 进行编码时遇到问题。我不知道整个代码是否错误,但无论如何我对此感到困惑。如何解决这个问题?

第一个 If-Then 语句不会给出任何错误,但代码中的第二个语句确实给出了错误。

我使用 Visual Studio Code 进行编码,并使用 Discord.js 作为 Node.js 模块。

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
    })
})

错误:

Declaration or statement expected ts(1128)

最佳答案

您缺少一个右大括号 - 这是您的确切代码,但已修复。

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
            })
    }
})

关于javascript - 如何修复 Discord.js 中的 "Declaration or statement expected. ts(1128)"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57430086/

相关文章:

javascript - 使用配置文件时的前缀问题

javascript - 如何使用嵌套 array.map 将板上的位置从 React JS 中的 Board 发送到 Cell 组件

javascript - 在 Node.js 中写入 CSV

node.js - Node 情况下的 Typescript IOC

javascript - Chrome 浏览器显示 NodeJS 代码计数错误

javascript - 不和谐收集器 react 过滤器方式设置最大限制

discord - discord,.js 上的无效 token

javascript - meteor 插件不起作用

javascript - 如何每 90 秒触发一次 Azure 计时器功能?

javascript - 奇怪的链接到/未定义 AngularJS