Trying to get user input for a Wordle game (interaction.channel is null)
Hi, I'm trying to create a slashcommand which takes in user input as guesses and compares it against a random word. I'm getting a TypeError though when running the code (below), which I feel I've narrowed down to interaction.channel being null itself. How do I fix this?
here's the error:
TypeError: Cannot read properties of null (reading 'createMessageCollector')
and here's the code:
``
const { SlashCommandBuilder } = require('discord.js');
// const fs = require('node:fs');
const { OpenAI } = require('openai');
module.exports = {
data: new SlashCommandBuilder()
.setName('startwordle')
.setDescription('starts a game of wordle~'),
async execute(interaction) {
// const dictionary = fs.readFileSync('dictionary.txt', 'utf-8').split('\n').filter(word => word.length === 5).map(word => word.toLowerCase());
await interaction.reply({ content:
Hi, ${interaction.user}. Starting a game of Wordle., ephemeral: true });
// const randomWord = await dictionary[Math.floor(Math.random() * dictionary.length)];
// const randomWord = await getRandom5LetterWordFromChatgpt();
const randomWord = 'SILLY';
let numGuesses = 3;
await interaction.followUp({ content: randomWord, ephemeral: true });
const gameStatus = true;
while (numGuesses > 0 && gameStatus == true) {
const collectorFilter = m => m.content.includes('discord');
const collector = interaction.channel.createMessageCollector({ filter: collectorFilter, time: 15_000 });
collector.on('collect', m => {
console.log(
Collected ${m.content});
});
collector.on('end', collected => {
console.log(
Collected ${collected.size} items`);
});
numGuesses--;
}
},
};5 Replies
- What's your exact discord.js
npm list discord.js
and node node -v
version?
- Not a discord.js issue? Check out #other-js-ts.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!
- ✅
Marked as resolved by OPdiscord.js is version 14.14.1
node.js is version 9.5.1
and the code is heavily adapted from the discord tutorial if that helps
oh im working collaboratively with people in a test server and don't want to spam them with bot messages while testing
well yeah that's true
but what could be the source of interaction.channel being null? @Qjuh
oh i see, sounds like a lot of things. I checked guilds intent and it should be good ([GatewayIntentBits.Guilds] + checked off messages in the app). What exactly does missing bot scope mean?
oh wait no
i'm gonna add it real quick
ok just added it
Unknown User•8mo ago
Message Not Public
Sign In & Join Server To View
ohhhh that makes sense
that was why i was able to print stuff
alright it's all settled out now, input is working! thanks guys
Unknown User•8mo ago
Message Not Public
Sign In & Join Server To View