spunkir
spunkir
DIAdiscord.js - Imagine a bot
Created by spunkir on 6/29/2023 in #djs-questions
Bot crashing when calling custom /suggest command
Current code:
// Import required dependencies
const { SlashCommandBuilder } = require("@discordjs/builders");
const { EmbedBuilder } = require("discord.js");
const fs = require("fs").promises;

// Define the slash command
const suggestCommand = new SlashCommandBuilder()
.setName("suggest")
.setDescription("Make a suggestion for the bot")
.addStringOption((option) =>
option
.setName("suggestion")
.setDescription("Your suggestion")
.setRequired(true)
);

// Define the function to run when the command is used
async function suggest(interaction) {
// Get the suggestion from the user
const suggestion = interaction.options.getString("suggestion");

// Get the bot-suggestions channel
const botSuggestionsChannel = interaction.guild.channels.cache.find(
(channel) => channel.name === "bot-suggestions"
);

try {
// Write the suggestion to the file
await fs.appendFile("suggestions.txt", `${suggestion}\n`);
console.log(`Suggestion written to suggestions.txt: ${suggestion}`);

// Create an embed with the suggestion and user info
const embed = new EmbedBuilder()
.setColor("#0099ff")
.setTitle("New suggestion")
.setDescription(suggestion)
.addFields({
name: "User",
value: interaction.user.username || interaction.member.nickname,
inline: true,
})
.setTimestamp();

console.log("Embed built.");
console.log("Writing to channel: " + botSuggestionsChannel.name);
// Send the embed to the bot-suggestions channel
await botSuggestionsChannel.send(
"Hello world"
// { embeds: [embed] }
);
console.log("Suggestion sent to bot-suggestions channel.");

// Reply to the user with a confirmation message
await interaction.reply({
content: "Your suggestion has been received.",
});
console.log("Reply sent to user: Your suggestion has been received.");
} catch (error) {
console.log(error);
await interaction.reply({
content: "An error occurred while processing your suggestion.",
});
console.log("Error occurred while processing suggestion:", error);
}
}

// Export the command and execute function
module.exports = {
data: suggestCommand,
execute: suggest,
};
// Import required dependencies
const { SlashCommandBuilder } = require("@discordjs/builders");
const { EmbedBuilder } = require("discord.js");
const fs = require("fs").promises;

// Define the slash command
const suggestCommand = new SlashCommandBuilder()
.setName("suggest")
.setDescription("Make a suggestion for the bot")
.addStringOption((option) =>
option
.setName("suggestion")
.setDescription("Your suggestion")
.setRequired(true)
);

// Define the function to run when the command is used
async function suggest(interaction) {
// Get the suggestion from the user
const suggestion = interaction.options.getString("suggestion");

// Get the bot-suggestions channel
const botSuggestionsChannel = interaction.guild.channels.cache.find(
(channel) => channel.name === "bot-suggestions"
);

try {
// Write the suggestion to the file
await fs.appendFile("suggestions.txt", `${suggestion}\n`);
console.log(`Suggestion written to suggestions.txt: ${suggestion}`);

// Create an embed with the suggestion and user info
const embed = new EmbedBuilder()
.setColor("#0099ff")
.setTitle("New suggestion")
.setDescription(suggestion)
.addFields({
name: "User",
value: interaction.user.username || interaction.member.nickname,
inline: true,
})
.setTimestamp();

console.log("Embed built.");
console.log("Writing to channel: " + botSuggestionsChannel.name);
// Send the embed to the bot-suggestions channel
await botSuggestionsChannel.send(
"Hello world"
// { embeds: [embed] }
);
console.log("Suggestion sent to bot-suggestions channel.");

// Reply to the user with a confirmation message
await interaction.reply({
content: "Your suggestion has been received.",
});
console.log("Reply sent to user: Your suggestion has been received.");
} catch (error) {
console.log(error);
await interaction.reply({
content: "An error occurred while processing your suggestion.",
});
console.log("Error occurred while processing suggestion:", error);
}
}

// Export the command and execute function
module.exports = {
data: suggestCommand,
execute: suggest,
};
Current error logs with 'pm2 logs bot --err':
$ pm2 logs bot --err
[TAILING] Tailing last 15 lines for [bot] process (change the value with --lines option)
/home/ec2-user/.pm2/logs/bot-error.log last 15 lines:
0|bot | | CombinedPropertyError (1)
0|bot | | Received one or more errors
0|bot | |
0|bot | | input.value
0|bot | | | ValidationError > s.string
0|bot | | | Expected a string primitive
0|bot | | |
0|bot | | | Received:
0|bot | | | | [User]
0|bot |
0|bot | at ArrayValidator.handle (/home/ec2-user/OPEbot/node_modules/@sapphire/shapeshift/dist/index.js:468:70)
0|bot | at ArrayValidator.parse (/home/ec2-user/OPEbot/node_modules/@sapphire/shapeshift/dist/index.js:207:88)
0|bot | at EmbedBuilder.addFields (/home/ec2-user/OPEbot/node_modules/@discordjs/builders/dist/index.js:222:31)
0|bot | at Object.suggest [as execute] (/home/ec2-user/OPEbot/commands/moderation/suggest.js:37:8)
0|bot | at async Client.<anonymous> (/home/ec2-user/OPEbot/index.js:43:5)
$ pm2 logs bot --err
[TAILING] Tailing last 15 lines for [bot] process (change the value with --lines option)
/home/ec2-user/.pm2/logs/bot-error.log last 15 lines:
0|bot | | CombinedPropertyError (1)
0|bot | | Received one or more errors
0|bot | |
0|bot | | input.value
0|bot | | | ValidationError > s.string
0|bot | | | Expected a string primitive
0|bot | | |
0|bot | | | Received:
0|bot | | | | [User]
0|bot |
0|bot | at ArrayValidator.handle (/home/ec2-user/OPEbot/node_modules/@sapphire/shapeshift/dist/index.js:468:70)
0|bot | at ArrayValidator.parse (/home/ec2-user/OPEbot/node_modules/@sapphire/shapeshift/dist/index.js:207:88)
0|bot | at EmbedBuilder.addFields (/home/ec2-user/OPEbot/node_modules/@discordjs/builders/dist/index.js:222:31)
0|bot | at Object.suggest [as execute] (/home/ec2-user/OPEbot/commands/moderation/suggest.js:37:8)
0|bot | at async Client.<anonymous> (/home/ec2-user/OPEbot/index.js:43:5)
44 replies
DIAdiscord.js - Imagine a bot
Created by spunkir on 6/29/2023 in #djs-questions
Bot crashing when calling custom /suggest command
^
44 replies
DIAdiscord.js - Imagine a bot
Created by spunkir on 6/29/2023 in #djs-questions
Bot crashing when calling custom /suggest command
Oh I meant the timeout where it doesn't respond to the user in discord, not an actual timeout error
44 replies
DIAdiscord.js - Imagine a bot
Created by spunkir on 6/29/2023 in #djs-questions
Bot crashing when calling custom /suggest command
await botSuggestionsChannel.send("Hello world");
await botSuggestionsChannel.send("Hello world");
Also results in the timeout issue. Could it be the way that I'm setting the channel to send to?
// Get the bot-suggestions channel
const botSuggestionsChannel = interaction.guild.channels.cache.find(
(channel) => channel.name === "bot-suggestions"
);
// Get the bot-suggestions channel
const botSuggestionsChannel = interaction.guild.channels.cache.find(
(channel) => channel.name === "bot-suggestions"
);
44 replies
DIAdiscord.js - Imagine a bot
Created by spunkir on 6/29/2023 in #djs-questions
Bot crashing when calling custom /suggest command
That produces the same issue oddly enough. I also tried replacing the 'suggestion' variable with a static string and it resulted in the same issue
44 replies
DIAdiscord.js - Imagine a bot
Created by spunkir on 6/29/2023 in #djs-questions
Bot crashing when calling custom /suggest command
No dice on killing the pm2 either
44 replies
DIAdiscord.js - Imagine a bot
Created by spunkir on 6/29/2023 in #djs-questions
Bot crashing when calling custom /suggest command
Weird. git pull node index.js works, but running my wrapper is when I have issues (there's a git pull with the main repo above the top line):
# Stop the current bot instance
pm2 stop bot

# Run the deploy-commands.js script (assuming it is located in the bot directory)
node deploy-commands.js

# Start the bot using PM2
pm2 start index.js --name bot --watch
# Stop the current bot instance
pm2 stop bot

# Run the deploy-commands.js script (assuming it is located in the bot directory)
node deploy-commands.js

# Start the bot using PM2
pm2 start index.js --name bot --watch
44 replies
DIAdiscord.js - Imagine a bot
Created by spunkir on 6/29/2023 in #djs-questions
Bot crashing when calling custom /suggest command
Looks like even removing the fields produces the same error
44 replies
DIAdiscord.js - Imagine a bot
Created by spunkir on 6/29/2023 in #djs-questions
Bot crashing when calling custom /suggest command
Yeah I tried sending in the user.username, which should be a string, but haven't seen a difference:
// Create an embed with the suggestion and user info
const embed = new EmbedBuilder()
.setColor("#0099ff")
.setTitle("New suggestion")
.setDescription(suggestion)
.addFields({
name: "User",
value: interaction.user.username,
inline: true,
})
.setTimestamp();
// Create an embed with the suggestion and user info
const embed = new EmbedBuilder()
.setColor("#0099ff")
.setTitle("New suggestion")
.setDescription(suggestion)
.addFields({
name: "User",
value: interaction.user.username,
inline: true,
})
.setTimestamp();
44 replies
DIAdiscord.js - Imagine a bot
Created by spunkir on 6/29/2023 in #djs-questions
Bot crashing when calling custom /suggest command
Looks like pm2 has it's own logging system:
[TAILING] Tailing last 15 lines for [bot] process (change the value with --lines option)
/home/ec2-user/.pm2/logs/bot-error.log last 15 lines:
0|bot | | CombinedPropertyError (1)
0|bot | | Received one or more errors
0|bot | |
0|bot | | input.value
0|bot | | | ValidationError > s.string
0|bot | | | Expected a string primitive
0|bot | | |
0|bot | | | Received:
0|bot | | | | [User]
0|bot |
0|bot | at ArrayValidator.handle (/home/ec2-user/OPEbot/node_modules/@sapphire/shapeshift/dist/index.js:468:70)
0|bot | at ArrayValidator.parse (/home/ec2-user/OPEbot/node_modules/@sapphire/shapeshift/dist/index.js:207:88)
0|bot | at EmbedBuilder.addFields (/home/ec2-user/OPEbot/node_modules/@discordjs/builders/dist/index.js:222:31)
0|bot | at Object.suggest [as execute] (/home/ec2-user/OPEbot/commands/moderation/suggest.js:37:8)
0|bot | at async Client.<anonymous> (/home/ec2-user/OPEbot/index.js:43:5)
[TAILING] Tailing last 15 lines for [bot] process (change the value with --lines option)
/home/ec2-user/.pm2/logs/bot-error.log last 15 lines:
0|bot | | CombinedPropertyError (1)
0|bot | | Received one or more errors
0|bot | |
0|bot | | input.value
0|bot | | | ValidationError > s.string
0|bot | | | Expected a string primitive
0|bot | | |
0|bot | | | Received:
0|bot | | | | [User]
0|bot |
0|bot | at ArrayValidator.handle (/home/ec2-user/OPEbot/node_modules/@sapphire/shapeshift/dist/index.js:468:70)
0|bot | at ArrayValidator.parse (/home/ec2-user/OPEbot/node_modules/@sapphire/shapeshift/dist/index.js:207:88)
0|bot | at EmbedBuilder.addFields (/home/ec2-user/OPEbot/node_modules/@discordjs/builders/dist/index.js:222:31)
0|bot | at Object.suggest [as execute] (/home/ec2-user/OPEbot/commands/moderation/suggest.js:37:8)
0|bot | at async Client.<anonymous> (/home/ec2-user/OPEbot/index.js:43:5)
44 replies
DIAdiscord.js - Imagine a bot
Created by spunkir on 6/29/2023 in #djs-questions
Bot crashing when calling custom /suggest command
I don't have any that explicitly crash it, I am however running it on a pm2, so in the event that the bot does crash, it auto-restarts.
44 replies
DIAdiscord.js - Imagine a bot
Created by spunkir on 6/29/2023 in #djs-questions
Bot crashing when calling custom /suggest command
no, it outputs as expected:
Ready! Logged in as "OPE Bot#0931"
Suggestion written to suggestions.txt: testing
Embed built.
Writing to channel: bot-suggestions
Suggestion sent to bot-suggestions channel.
Reply sent to user: Your suggestion has been received.
Ready! Logged in as "OPE Bot#0931"
Suggestion written to suggestions.txt: testing
Embed built.
Writing to channel: bot-suggestions
Suggestion sent to bot-suggestions channel.
Reply sent to user: Your suggestion has been received.
44 replies
DIAdiscord.js - Imagine a bot
Created by spunkir on 6/29/2023 in #djs-questions
Bot crashing when calling custom /suggest command
I ran it on my local machine instead of my EC2 and it looks like it ran the command with no issue? The whole bot's stored in git and all leaves are updated
44 replies
DIAdiscord.js - Imagine a bot
Created by spunkir on 6/29/2023 in #djs-questions
Bot crashing when calling custom /suggest command
there's another log underneath the channel.send, but the bot looks like it's restarting before reaching it
44 replies
DIAdiscord.js - Imagine a bot
Created by spunkir on 6/29/2023 in #djs-questions
Bot crashing when calling custom /suggest command
the current structure is: log "embed built" log "writing to channel..." channel.send embed
44 replies
DIAdiscord.js - Imagine a bot
Created by spunkir on 6/29/2023 in #djs-questions
Bot crashing when calling custom /suggest command
i.e. line 43
44 replies
DIAdiscord.js - Imagine a bot
Created by spunkir on 6/29/2023 in #djs-questions
Bot crashing when calling custom /suggest command
how so? how would you catch the await botSuggestionsChannel.send([ embeds: [embed] }); ?
44 replies
DIAdiscord.js - Imagine a bot
Created by spunkir on 6/29/2023 in #djs-questions
Bot crashing when calling custom /suggest command
/home/ec2-user/.pm2/logs/bot-out.log last 15 lines:
0|bot | Ready! Logged in as "OPE Bot#0931"
0|bot | Ready! Logged in as "OPE Bot#0931"
0|bot | Suggestion written to suggestions.txt: eat dick
0|bot | Embed built.
0|bot | Ready! Logged in as "OPE Bot#0931"
0|bot | Suggestion written to suggestions.txt: who?
0|bot | Embed built.
0|bot | Ready! Logged in as "OPE Bot#0931"
0|bot | Ready! Logged in as "OPE Bot#0931"
0|bot | Ready! Logged in as "OPE Bot#0931"
0|bot | Ready! Logged in as "OPE Bot#0931"
0|bot | Suggestion written to suggestions.txt: eat my ass
0|bot | Embed built.
0|bot | Ready! Logged in as "OPE Bot#0931"
0|bot | Ready! Logged in as "OPE Bot#0931"

0|bot | Suggestion written to suggestions.txt: this guy's a murderer
0|bot | Embed built.
0|bot | Writing to channel: bot-suggestions
0|bot | Ready! Logged in as "OPE Bot#0931"
0|bot | Suggestion written to suggestions.txt: goddamn dude
0|bot | Embed built.
0|bot | Writing to channel: bot-suggestions
0|bot | Ready! Logged in as "OPE Bot#0931"
/home/ec2-user/.pm2/logs/bot-out.log last 15 lines:
0|bot | Ready! Logged in as "OPE Bot#0931"
0|bot | Ready! Logged in as "OPE Bot#0931"
0|bot | Suggestion written to suggestions.txt: eat dick
0|bot | Embed built.
0|bot | Ready! Logged in as "OPE Bot#0931"
0|bot | Suggestion written to suggestions.txt: who?
0|bot | Embed built.
0|bot | Ready! Logged in as "OPE Bot#0931"
0|bot | Ready! Logged in as "OPE Bot#0931"
0|bot | Ready! Logged in as "OPE Bot#0931"
0|bot | Ready! Logged in as "OPE Bot#0931"
0|bot | Suggestion written to suggestions.txt: eat my ass
0|bot | Embed built.
0|bot | Ready! Logged in as "OPE Bot#0931"
0|bot | Ready! Logged in as "OPE Bot#0931"

0|bot | Suggestion written to suggestions.txt: this guy's a murderer
0|bot | Embed built.
0|bot | Writing to channel: bot-suggestions
0|bot | Ready! Logged in as "OPE Bot#0931"
0|bot | Suggestion written to suggestions.txt: goddamn dude
0|bot | Embed built.
0|bot | Writing to channel: bot-suggestions
0|bot | Ready! Logged in as "OPE Bot#0931"
44 replies
DIAdiscord.js - Imagine a bot
Created by spunkir on 6/29/2023 in #djs-questions
Bot crashing when calling custom /suggest command
The 0 | bot output is the only log I have
44 replies
DIAdiscord.js - Imagine a bot
Created by spunkir on 6/29/2023 in #djs-questions
Bot crashing when calling custom /suggest command
got it lmao
44 replies