Waiting for user message in DM.
I've been trying to get the bot to wait for a message but it keeps logging this error
Here is my code.
I'd love a few pointers of where im going wrong <3
TypeError: Cannot read properties of null (reading 'awaitMessages')
at Object.execute (/Users/kirakenjiro/Desktop/Coding/Active/AkedasBot/commands/verify.js:31:61)
at Client.<anonymous> (/Users/kirakenjiro/Desktop/Coding/Active/AkedasBot/index.js:80:19)
at Client.emit (node:events:514:28)
at InteractionCreateAction.handle (/Users/kirakenjiro/node_modules/discord.js/src/client/actions/InteractionCreate.js:97:12)TypeError: Cannot read properties of null (reading 'awaitMessages')
at Object.execute (/Users/kirakenjiro/Desktop/Coding/Active/AkedasBot/commands/verify.js:31:61)
at Client.<anonymous> (/Users/kirakenjiro/Desktop/Coding/Active/AkedasBot/index.js:80:19)
at Client.emit (node:events:514:28)
at InteractionCreateAction.handle (/Users/kirakenjiro/node_modules/discord.js/src/client/actions/InteractionCreate.js:97:12)Here is my code.
const { EmbedBuilder } = require("discord.js");
const handlers = require("../handlerLoader.js");
module.exports = {
name: "verify",
description: "Sends your ID to the moderators to be verified for the 18+ channels",
async execute(interaction) {
// Check if the command was sent in a DM channel
if (interaction.guildId) {
// Send an embed indicating that the command must be executed in a DM
const warningEmbed = new EmbedBuilder()
.setColor(0x2b2d31)
.setAuthor({
name: "Verification Error",
})
.setDescription(
'This command must be executed in a DM (Direct Message) channel.\nYour legal ID was not processed.'
);
await interaction.reply({
embeds: [warningEmbed],
ephemeral: true,
});
} else {
// Wait for 30 seconds in the DM
const filter = (msg) => msg.author.id === interaction.user.id;
const options = { max: 1, time: 30000, errors: ["time"] };
try {
const collected = await interaction.channel.awaitMessages(filter, options);
const message = collected.first();
// Check if the message contains an image
if (message && message.attachments.size > 0) {
const imageUrl = message.attachments.first().url;
console.log(`Image URL: ${imageUrl}`);
}
} catch (error) {
console.error(error);
}
}
}
};const { EmbedBuilder } = require("discord.js");
const handlers = require("../handlerLoader.js");
module.exports = {
name: "verify",
description: "Sends your ID to the moderators to be verified for the 18+ channels",
async execute(interaction) {
// Check if the command was sent in a DM channel
if (interaction.guildId) {
// Send an embed indicating that the command must be executed in a DM
const warningEmbed = new EmbedBuilder()
.setColor(0x2b2d31)
.setAuthor({
name: "Verification Error",
})
.setDescription(
'This command must be executed in a DM (Direct Message) channel.\nYour legal ID was not processed.'
);
await interaction.reply({
embeds: [warningEmbed],
ephemeral: true,
});
} else {
// Wait for 30 seconds in the DM
const filter = (msg) => msg.author.id === interaction.user.id;
const options = { max: 1, time: 30000, errors: ["time"] };
try {
const collected = await interaction.channel.awaitMessages(filter, options);
const message = collected.first();
// Check if the message contains an image
if (message && message.attachments.size > 0) {
const imageUrl = message.attachments.first().url;
console.log(`Image URL: ${imageUrl}`);
}
} catch (error) {
console.error(error);
}
}
}
};I'd love a few pointers of where im going wrong <3