I’m a new discord.js programmer. I’m trying to create a command that, once triggered, will listen for a message and send a reply. Right now, I am trying to get any form of response to the function, but neither the console.log or the message.reply methods are returning any value.
I believe my issue is with the client.on() method, I should have all of my intents in order.
Before it’s asked, I’m calling Events from discord.js because I’ve been using both "messageCreate" and Events.messageCreate interchangeably within testing. Neither is returning information.
My code (replier.js) is-
const { SlashCommandBuilder, Events, Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers
] ,
partials: ['MESSAGE', 'CHANNEL', 'REACTION'] });
module.exports = {
data: new SlashCommandBuilder()
.setName('replier')
.setDescription('Responds to your input!'),
async execute(interaction){
await interaction.reply('Initial Message. Type a response')
client.on("messageCreate", (message) => {
console.log('Recieved Input')
message.reply('Text')})}}
Once the user enters /replier on discord, the expected response is for the bot to send the Initial Message, and wait for a reply from the user. Currently, no response is being given
2
Answers
Intents
Make sure you have also enabled the
MessageContent
intent in the developer portalDiscord Events
A Discord event should only be defined whenever you want the bot to do something every time that specific event is fired. Normally you would define these event listeners in the root of your code.
If you want your bot to listen to one or more messages when someone uses the
replier
command I’d suggest you use message collectors. Using a collector you can tell your bot to collect a set amount of messages that match the given filter. Here’s an exampleI don’t know why you are trying to use an eventListener here when you should be using something like
interaction.channel.awaitMessages(...)
, heres the link to the documentation: https://discord.js.org/docs/packages/discord.js/main/BaseGuildTextChannel:Class#awaitMessagesSo basically instead of the whole
client.on(...)
eventListener, use this:and since you are already using async, you don’t even need to make the function asynchronous.
Now you have the msg from the user, you can do whatever you need with it.
I hope this helps!