Skip to content

Commit 9202e61

Browse files
authored
🚀 release: v2.0.9
Merge pull request #89 from thirdweb-dev/v2
2 parents 2d33507 + 983db4d commit 9202e61

File tree

2 files changed

+47
-24
lines changed

2 files changed

+47
-24
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "thirdweb-support-discord-bot",
3-
"version": "2.0.8",
3+
"version": "2.0.9",
44
"description": "A self-hosted dedicated forum-based support Discord bot for the thirdweb community.",
55
"main": "src/bot.ts",
66
"author": "Waren Gonzaga",

src/bot.js

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -73,34 +73,57 @@ client.on("messageCreate", async (message) => {
7373
// respond to ask command
7474
if ((message.content.startsWith('!askai') || message.content.startsWith('!ask'))) {
7575
let question = message.content.startsWith('!askai') ? message.content.slice(6) : message.content.slice(4);
76-
if (message.channel.id === ASKAI_CHANNEL) {
77-
let aiMessageLoading = await message.channel.send({
78-
embeds: [
79-
sendEmbedMessage("**🤖 Beep Boop Boop Beep:** " + `<a:load:1210497921158619136> thinking...`),
80-
],
81-
});
82-
83-
try {
84-
const query = await context.query({
85-
botId: CONTEXT_ID,
86-
query: question
87-
});
76+
const gettingStartedASKAI = `Hello, kindly use \`!ask\` or \`!askai\` followed by your question to get started.`;
8877

89-
const msg = await message.channel.messages.fetch(aiMessageLoading.id);
90-
await msg.edit({
91-
content: `Hey <@${message.author.id}> 👇`,
78+
// check if there's a question, if not, send the getting started message, if there's a question, send the response
79+
if (!question) {
80+
message.reply({
81+
content: `Hey <@${message.author.id}> 👇`,
82+
embeds: [sendEmbedMessage(gettingStartedASKAI)],
83+
});
84+
} else {
85+
if (message.channel.id === ASKAI_CHANNEL) {
86+
let aiMessageLoading = await message.channel.send({
9287
embeds: [
93-
sendEmbedMessage(`**Response:**\n${query.output.toString()}`),
88+
sendEmbedMessage("**🤖 Beep Boop Boop Beep:** " + `<a:load:1210497921158619136> thinking...`),
9489
],
9590
});
96-
} catch (error) {
97-
console.error(error);
91+
92+
try {
93+
const query = await context.query({
94+
botId: CONTEXT_ID,
95+
query: question
96+
});
97+
98+
if (query && query.output) {
99+
const msg = await message.channel.messages.fetch(aiMessageLoading.id);
100+
await msg.edit({
101+
content: `Hey <@${message.author.id}> 👇`,
102+
embeds: [
103+
sendEmbedMessage(`**Response:**\n${query.output.toString()}`),
104+
],
105+
});
106+
} else {
107+
console.error('[Error]: query or query.output is undefined');
108+
console.log(query);
109+
const msg = await message.channel.messages.fetch(aiMessageLoading.id);
110+
await msg.edit({
111+
content: `Hey <@${message.author.id}> 👇`,
112+
embeds: [
113+
sendEmbedMessage(`**Response:**\nI'm sorry, I couldn't find a response to your question. Please try again later.`),
114+
],
115+
});
116+
}
117+
} catch (error) {
118+
console.error(error);
119+
}
120+
} else {
121+
// if the command is not from the channel
122+
message.reply({
123+
content: `Hey <@${message.author.id}> 👇`,
124+
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.`)],
125+
});
98126
}
99-
} else {
100-
message.reply({
101-
content: `Hey <@${message.author.id}> 👇`,
102-
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.`)],
103-
});
104127
}
105128
}
106129
// respond to user if the bot mentioned specifically not with everyone

0 commit comments

Comments
 (0)