I am writing a private bot. When I wanted to make a command with option to ping another user. However, when I try to run it i am getting an error:
TypeError: " " is not a function
This is my code:
const { Client, Events, GatewayIntentBits, SlashCommandBuilder, REST, Routes } = require('discord.js');
const {token} = require('./config.json');
const client = new Client({intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers]});
client.once(Events.ClientReady, c => {
console.log(`Logged in as ${c.user.tag}`);
const ping = new SlashCommandBuilder()
.setName('ping')
.setDescription('Pings another user')
.addUserOption(option =>
option
.setName('pingd')
.setDescription('Who to ping?')
.setRequired(false)
)
.setIntegrationTypes(0, 1)
.setContexts(0, 1, 2);
const noni = new SlashCommandBuilder()
.setName('noni')
.setDescription('Test command')
.setIntegrationTypes(0, 1)
.setContexts(0, 1, 2);
client.application.commands.create(ping);
client.application.commands.create(noni);
});
client.on(Events.InteractionCreate, interaction => {
if(!interaction.isChatInputCommand()) return;
if(interaction.commandName === "ping"){
let user = interaction.options.getUser('pingd');
if (!user) user = interaction.user;
console.log(user)
interaction.reply(` ``test``n @${user.username}`);
}
if(interaction.commandName === "noni"){
interaction.reply(` ``another test!`` `);
}
console.log(interaction);
});
client.login(token);
How can i fix it?
Thanks
I have tried to remove @${user.username}
section, but it didn’t work.