TypeError // Text mirror command not working
Hello, so I'm trying to create a command that mirrors the text the user inputs, the only problem I have is I can't find a way to create an option for the user to input text in, and I get this error message when I run the command:
Relevant index.js code
Relevant register-commands.js code
I have tried to research in the Discord.JS documentation, but it's really cryptic and hard to understand (as I'm a beginner), thank you in advance.
this.ephemeral = options.ephemeral ?? false;
^
TypeError: Cannot read properties of null (reading 'ephemeral')
this.ephemeral = options.ephemeral ?? false;
^
TypeError: Cannot read properties of null (reading 'ephemeral')
client.on('interactionCreate', (interaction) => {
if (!interaction.isChatInputCommand()) return;
const interactionChannel = interaction.channel;
if (interaction.commandName === 'mirror') {
const mirrorMessage = interaction.options.get('mirror-message');
interaction.reply(mirrorMessage);
}
client.on('interactionCreate', (interaction) => {
if (!interaction.isChatInputCommand()) return;
const interactionChannel = interaction.channel;
if (interaction.commandName === 'mirror') {
const mirrorMessage = interaction.options.get('mirror-message');
interaction.reply(mirrorMessage);
}
{
name: 'mirror',
description: 'mirrors your text',
options: [
{
name: 'mirror-message',
description: 'テキスト',
type: ApplicationCommandOptionType.String,
required: true,
},
]
},
{
name: 'mirror',
description: 'mirrors your text',
options: [
{
name: 'mirror-message',
description: 'テキスト',
type: ApplicationCommandOptionType.String,
required: true,
},
]
},
8 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 version is 14.14.1, and node version is v20.11.1
Unknown User•8mo ago
Message Not Public
Sign In & Join Server To View
Hello,
did that, still gives an error
I'm trying to find what I'm doing wrong with the command definition itself in the register-commands file
this is the commands file
C:\Users\DostenditeD\Desktop\Stuff\自作\コディング\Discord Bots\ボタン\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:103
this.ephemeral = options.ephemeral ?? false;
^
TypeError: Cannot read properties of null (reading 'ephemeral')
at ChatInputCommandInteraction.reply (C:\Users\DostenditeD\Desktop\Stuff\自作\コディング\Discord Bots\ボタン\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:103:30)
at Client.<anonymous> (C:\Users\DostenditeD\Desktop\Stuff\自作\コディング\Discord Bots\ボタン\src\index.js:69:21)
at Client.emit (node:events:518:28)
at InteractionCreateAction.handle (C:\Users\DostenditeD\Desktop\Stuff\自作\コディング\Discord Bots\ボタン\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] (C:\Users\DostenditeD\Desktop\Stuff\自作\コディング\Discord Bots\ボタン\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (C:\Users\DostenditeD\Desktop\Stuff\自作\コディング\Discord Bots\ボタン\node_modules\discord.js\src\client\websocket\WebSocketManager.js:355:31)
at WebSocketManager.<anonymous> (C:\Users\DostenditeD\Desktop\Stuff\自作\コディング\Discord Bots\ボタン\node_modules\discord.js\src\client\websocket\WebSocketManager.js:239:12)
at WebSocketManager.emit (C:\Users\DostenditeD\Desktop\Stuff\自作\コディング\Discord Bots\ボタン\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
at WebSocketShard.<anonymous> (C:\Users\DostenditeD\Desktop\Stuff\自作\コディング\Discord Bots\ボタン\node_modules\@discordjs\ws\dist\index.js:1173:51)
at WebSocketShard.emit (C:\Users\DostenditeD\Desktop\Stuff\自作\コディング\Discord Bots\ボタン\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
Node.js v20.11.1
C:\Users\DostenditeD\Desktop\Stuff\自作\コディング\Discord Bots\ボタン\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:103
this.ephemeral = options.ephemeral ?? false;
^
TypeError: Cannot read properties of null (reading 'ephemeral')
at ChatInputCommandInteraction.reply (C:\Users\DostenditeD\Desktop\Stuff\自作\コディング\Discord Bots\ボタン\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:103:30)
at Client.<anonymous> (C:\Users\DostenditeD\Desktop\Stuff\自作\コディング\Discord Bots\ボタン\src\index.js:69:21)
at Client.emit (node:events:518:28)
at InteractionCreateAction.handle (C:\Users\DostenditeD\Desktop\Stuff\自作\コディング\Discord Bots\ボタン\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] (C:\Users\DostenditeD\Desktop\Stuff\自作\コディング\Discord Bots\ボタン\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (C:\Users\DostenditeD\Desktop\Stuff\自作\コディング\Discord Bots\ボタン\node_modules\discord.js\src\client\websocket\WebSocketManager.js:355:31)
at WebSocketManager.<anonymous> (C:\Users\DostenditeD\Desktop\Stuff\自作\コディング\Discord Bots\ボタン\node_modules\discord.js\src\client\websocket\WebSocketManager.js:239:12)
at WebSocketManager.emit (C:\Users\DostenditeD\Desktop\Stuff\自作\コディング\Discord Bots\ボタン\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
at WebSocketShard.<anonymous> (C:\Users\DostenditeD\Desktop\Stuff\自作\コディング\Discord Bots\ボタン\node_modules\@discordjs\ws\dist\index.js:1173:51)
at WebSocketShard.emit (C:\Users\DostenditeD\Desktop\Stuff\自作\コディング\Discord Bots\ボタン\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
Node.js v20.11.1
const commands = [
{
name: 'add',
description: 'Adds two numbers.',
options: [
{
name: 'first-number',
description: 'The first number.',
type: ApplicationCommandOptionType.Number,
choices: [
{
name: '十',
value: 10,
},
{
name: '七',
value: 7,
},
],
required: true,
},
{
name: 'second-number',
description: 'The second number.',
type: ApplicationCommandOptionType.Number,
choices: [
{
name: '五',
value: 5,
},
{
name: '三',
value: 3,
},
],
required: true,
},
]
},
{
name: 'embed',
description: 'Sends an embed',
},
{
name: 'number-game',
description: 'Play a number game',
},
{
name: 'mirror',
description: 'mirrors your text',
options: [
{
name: 'mirror-message',
description: 'テキスト',
type: ApplicationCommandOptionType.String,
required: true,
},
]
},
];
const commands = [
{
name: 'add',
description: 'Adds two numbers.',
options: [
{
name: 'first-number',
description: 'The first number.',
type: ApplicationCommandOptionType.Number,
choices: [
{
name: '十',
value: 10,
},
{
name: '七',
value: 7,
},
],
required: true,
},
{
name: 'second-number',
description: 'The second number.',
type: ApplicationCommandOptionType.Number,
choices: [
{
name: '五',
value: 5,
},
{
name: '三',
value: 3,
},
],
required: true,
},
]
},
{
name: 'embed',
description: 'Sends an embed',
},
{
name: 'number-game',
description: 'Play a number game',
},
{
name: 'mirror',
description: 'mirrors your text',
options: [
{
name: 'mirror-message',
description: 'テキスト',
type: ApplicationCommandOptionType.String,
required: true,
},
]
},
];
Unknown User•8mo ago
Message Not Public
Sign In & Join Server To View
Hey, that's the commands array
I don't know if I'm not asking for help correctly as I've read the guidelines and made my own research & troubleshooting beforehand,
but I just can't pin this one down, and it's frustrating because it's such an incredibly simple feature I'm trying to code
all I want to do is ask the user for input and give that input a name when creating a command
C:\Users\DostenditeD\Desktop\Stuff\自作\コディング\Discord Bots\ボタン\src\index.js:69 interaction.channel.send(mirrorMessage.content);
^
TypeError: Cannot read properties of null (reading 'content')
at Client.<anonymous> (C:\Users\DostenditeD\Desktop\Stuff\自作\コディング\Discord Bots\ボタン\src\index.js:69:48)
at Client.emit (node:events:518:28)
at InteractionCreateAction.handle (C:\Users\DostenditeD\Desktop\Stuff\自作\コディング\Discord Bots\ボタン\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] (C:\Users\DostenditeD\Desktop\Stuff\自作\コディング\Discord Bots\ボタン\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (C:\Users\DostenditeD\Desktop\Stuff\自作\コディング\Discord Bots\ボタン\node_modules\discord.js\src\client\websocket\WebSocketManager.js:355:31)
at WebSocketManager.<anonymous> (C:\Users\DostenditeD\Desktop\Stuff\自作\コディング\Discord Bots\ボタン\node_modules\discord.js\src\client\websocket\WebSocketManager.js:239:12)
at WebSocketManager.emit (C:\Users\DostenditeD\Desktop\Stuff\自作\コディング\Discord Bots\ボタン\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
at WebSocketShard.<anonymous> (C:\Users\DostenditeD\Desktop\Stuff\自作\コディング\Discord Bots\ボタン\node_modules\@discordjs\ws\dist\index.js:1173:51)
at WebSocketShard.emit (C:\Users\DostenditeD\Desktop\Stuff\自作\コディング\Discord Bots\ボタン\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
at WebSocketShard.onMessage (C:\Users\DostenditeD\Desktop\Stuff\自作\コディング\Discord Bots\ボタン\node_modules\@discordjs\ws\dist\index.js:988:14)
C:\Users\DostenditeD\Desktop\Stuff\自作\コディング\Discord Bots\ボタン\src\index.js:69 interaction.channel.send(mirrorMessage.content);
^
TypeError: Cannot read properties of null (reading 'content')
at Client.<anonymous> (C:\Users\DostenditeD\Desktop\Stuff\自作\コディング\Discord Bots\ボタン\src\index.js:69:48)
at Client.emit (node:events:518:28)
at InteractionCreateAction.handle (C:\Users\DostenditeD\Desktop\Stuff\自作\コディング\Discord Bots\ボタン\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12)
at module.exports [as INTERACTION_CREATE] (C:\Users\DostenditeD\Desktop\Stuff\自作\コディング\Discord Bots\ボタン\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (C:\Users\DostenditeD\Desktop\Stuff\自作\コディング\Discord Bots\ボタン\node_modules\discord.js\src\client\websocket\WebSocketManager.js:355:31)
at WebSocketManager.<anonymous> (C:\Users\DostenditeD\Desktop\Stuff\自作\コディング\Discord Bots\ボタン\node_modules\discord.js\src\client\websocket\WebSocketManager.js:239:12)
at WebSocketManager.emit (C:\Users\DostenditeD\Desktop\Stuff\自作\コディング\Discord Bots\ボタン\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
at WebSocketShard.<anonymous> (C:\Users\DostenditeD\Desktop\Stuff\自作\コディング\Discord Bots\ボタン\node_modules\@discordjs\ws\dist\index.js:1173:51)
at WebSocketShard.emit (C:\Users\DostenditeD\Desktop\Stuff\自作\コディング\Discord Bots\ボタン\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
at WebSocketShard.onMessage (C:\Users\DostenditeD\Desktop\Stuff\自作\コディング\Discord Bots\ボタン\node_modules\@discordjs\ws\dist\index.js:988:14)