該当コード
js
1const http = require("http"); 2const querystring = require("querystring"); 3const discord = require("discord.js"); 4const client = new discord.Client(); 5const prefix = process.env.prefix; 6try { 7 // GAS(Google Apps Script)からの受信(botの常時起動) 8 http.createServer(function(req, res){ 9 res.write("OKDiscordでオンラインになっているはずです"); 10 res.end(); 11 }).listen(8080); 12 client.on("ready", message => { 13 console.log("Bot準備完了~Discordでオンラインになっているか確認してください"); 14 client.user.setActivity(process.env.activity, { type: process.env.acttype }); 15 }); 16client.on("message", async message => { 17 if (message.author.id == client.user.id || message.author.bot) return; 18 if (message.mentions.has(client.user)) { 19 message.reply("呼びましたか?b!helpなどでできます") 20 } 21 if (!message.content.startsWith(prefix)) return; //ボットのプレフィックスからメッセージが始まっているか確認 22 const args = message.content.slice(prefix.length).trim().split(/ +/g); 23 const command = args.shift().toLowerCase(); 24 if (command === "help") { //コマンド名 25 message.channel.send({ 26 embed: { 27 title: "ヘルプ", 28 description: "全てのコマンドの初めに`" + prefix + "`をつける必要があります。", 29 fields: [ 30 { 31 name: "ヘルプ", 32 value: "`help`" 33 } 34 ] 35 } 36 }); 37 } 38}); 39 if (process.env.DISCORD_BOT_TOKEN == undefined) { 40 console.log("DISCORD_BOT_TOKENが設定されていません。"); 41 process.exit(0); 42 } 43 client.login(process.env.DISCORD_BOT_TOKEN); 44} catch (e) { 45 console.log(e); 46}
実現したいこと
コマンドを増やしたい!!
###エラーコード
SyntaxError: Missing catch or finally after try
###エラーが出たコード
js
1const http = require("http"); 2const querystring = require("querystring"); 3const discord = require("discord.js"); 4const client = new discord.Client(); 5const prefix = process.env.prefix; 6try { 7 // GAS(Google Apps Script)からの受信(botの常時起動) 8 http.createServer(function(req, res){ 9 res.write("OKDiscordでオンラインになっているはずです"); 10 res.end(); 11 }).listen(8080); 12 client.on("ready", message => { 13 console.log("Bot準備完了~Discordでオンラインになっているか確認してください"); 14 client.user.setActivity(process.env.activity, { type: process.env.acttype }); 15 }); 16client.on("message", async message => { 17 if (message.author.id == client.user.id || message.author.bot) return; 18 if (message.mentions.has(client.user)) { 19 message.reply("呼びましたか?b!helpなどでできます") 20 } 21 if (!message.content.startsWith(prefix)) return; //ボットのプレフィックスからメッセージが始まっているか確認 22 const args = message.content.slice(prefix.length).trim().split(/ +/g); 23 const command = args.shift().toLowerCase(); 24 if (command === "help") { //コマンド名 25 message.channel.send({ 26 embed: { 27 title: "ヘルプ", 28 description: "全てのコマンドの初めに`" + prefix + "`をつける必要があります。", 29 fields: [ 30 { 31 name: "ヘルプ", 32 value: "`help`" 33 } 34 ] 35 } 36 }); 37 } 38}); 39 if (command === "tata") { //コマンド名 40 message.channel.send({ 41 embed: { 42 title: "tata", 43 description: "全てのコマンドの初めに`" + prefix + "`をつける必要があります。", 44 description: "今稼働中のbotは"+"8"+"台です", 45 fields: [ 46 { 47 name: "tata", 48 value: "`tata`" 49 } 50 ] 51 } 52 }); 53 } 54}); 55 if (process.env.DISCORD_BOT_TOKEN == undefined) { 56 console.log("DISCORD_BOT_TOKENが設定されていません。"); 57 process.exit(0); 58 } 59 client.login(process.env.DISCORD_BOT_TOKEN); 60} catch (e) { 61 console.log(e); 62}
こちらの質問が複数のユーザーから「調査したこと・試したことが記載されていない質問」という指摘を受けました。
回答1件