diff --git a/package.json b/package.json index ccf7273..2331fbb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "thirdweb-support-discord-bot", - "version": "2.0.7", + "version": "2.0.8", "description": "A self-hosted dedicated forum-based support Discord bot for the thirdweb community.", "main": "src/bot.ts", "author": "Waren Gonzaga", diff --git a/src/bot.js b/src/bot.js index aad9722..8f01d0c 100644 --- a/src/bot.js +++ b/src/bot.js @@ -70,34 +70,38 @@ client.on("messageCreate", async (message) => { }); console.log(`[log]: responded to version command in version ${version}`); } - if (message.channel.id === ASKAI_CHANNEL && message.content.startsWith('!askai') || message.channel.id === ASKAI_CHANNEL && message.content.startsWith('!ask')) { - let question = message.content.startsWith('!askai') ? message.content.slice(6) : message.content.slice(4) - let aiMessageLoading = await message.channel.send({ - embeds: [ - sendEmbedMessage("**🤖 Beep Boop Boop Beep:** " + ` thinking...`), - ], - }); - await context.query({ - botId: CONTEXT_ID, - query: question, - onComplete: async (query) => { - // console.log(query.output.toString()) - await message.channel.messages.fetch(aiMessageLoading.id).then((msg) => - msg.edit({ - content: `Hey <@${message.author.id}> 👇`, - embeds: [ - sendEmbedMessage(`**Response:**\n${query.output.toString()}`), - ], - - }) - ); - - }, - onError: (error) => { - console.error(error); - }, - }); + // respond to ask command + if ((message.content.startsWith('!askai') || message.content.startsWith('!ask'))) { + let question = message.content.startsWith('!askai') ? message.content.slice(6) : message.content.slice(4); + if (message.channel.id === ASKAI_CHANNEL) { + let aiMessageLoading = await message.channel.send({ + embeds: [ + sendEmbedMessage("**🤖 Beep Boop Boop Beep:** " + ` thinking...`), + ], + }); + try { + const query = await context.query({ + botId: CONTEXT_ID, + query: question + }); + + const msg = await message.channel.messages.fetch(aiMessageLoading.id); + await msg.edit({ + content: `Hey <@${message.author.id}> 👇`, + embeds: [ + sendEmbedMessage(`**Response:**\n${query.output.toString()}`), + ], + }); + } catch (error) { + console.error(error); + } + } else { + message.reply({ + content: `Hey <@${message.author.id}> 👇`, + embeds: [sendEmbedMessage(`You can ask me all things thirdweb in the <#${ASKAI_CHANNEL}> channel. Just type your question after the command \`!askai\` or \`!ask\` to get started.`)], + }); + } } // respond to user if the bot mentioned specifically not with everyone if (message.mentions.has(client.user) && !message.mentions.everyone) {