admin管理员组文章数量:1326093
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:
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 3Declaration or statement expected ts(1128)
-
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
1 Answer
Reset to default 3You 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
})
}
})
本文标签: javascriptHow do I fix quotDeclaration or statement expected ts(1128)quot in DiscordjsStack Overflow
版权声明:本文标题:javascript - How do I fix "Declaration or statement expected. ts(1128)" in Discord.js? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742194447a2430816.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论