Asuka
Asuka

Reputation: 82

How to make the discord bot answer my commands

Node version: 16

The error is in sendMessage it said:

Property 'sendMessage' does not exist on type 'TextBasedChannels'. Property 'sendMessage' does not exist on type 'DMChannel'.

So when I type node . in terminal,it shows me no errors but on discord when I type !info or !version, the bot does not answer me.

What I wrote:

const { Client, Intents } = require('discord.js');

const bot = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });

const token ='MY TOKEN';

const PREFIX ='!';

var version = '1.0.1';

bot.on('ready', () =>{
    console.log('This bot is online!');
})

bot.on("message", message=>{
    
    let args = message.content.substring(PREFIX.length).split(" ");

    switch(args[0]){
        case 'ping':
            message.channel.sendMessage('pong!')
            break;
        case 'website':
            message.channel.sendMessage('youtube.com')
            break;
        case 'info':
            if (args[1] === 'version'){
            message.channel.sendMessage('Version ' + version);
            }else{
                message.channel.sendMessage('Invalid Args')
            }
        break;
    }
})   
    
bot.login(token);```

Upvotes: 2

Views: 71

Answers (1)

Lofn
Lofn

Reputation: 940

It is because you should use .send() there is no such thing as .sendMessage()

Upvotes: 1

Related Questions