title: How to make a bot execute a command via messages in discord? Mineflayer bot
body: <p>I use the bot's Mineflayer and want it to be synchronized with the discord afterwards. At the moment, the bot outputs the game chat from minecraft to discord. And I want to be able to, say, write .runcmd /help and execute the /help command. But for some reason when I enter .runcmd nothing happens.</p>
  <pre><code>const { Client, GatewayIntentBits } = require('discord.js');
  const client = new Discord.Client({
    intents: [
      GatewayIntentBits.Guilds,
      GatewayIntentBits.GuildMessages,
    ]
  })
  const mineflayer = require('mineflayer');
  
  let channel = client.channels.cache.get(&quot;id discord channel&quot;)
  let sending = false;
  let chatData = [];
  
  let bot = mineflayer.createBot({
    username: 'nick',
    host: 'ip',
    version: 'version',
  })
  
  client.on(&quot;ready&quot;, async =&gt;{
    console.log(&quot;Ingame Bot Online&quot;)
  })
  
  bot.once('spawn', function () {
    bot.chat('/server1')
  })
  
  bot.on(&quot;message&quot;, message =&gt; {
    if (sending == true) {
      chatData.push(`${message}`)
    }
  })
  
  client.on(&quot;message&quot;, async msg =&gt; {
    let args = msg.content.split(&quot; &quot;).slice(1)
    
    if(msg.content.startsWith(&quot;.runcmd&quot;)) {
      let toSend = args.join(&quot; &quot;);
      if(!toSend) return msg.reply(&quot;No Args&quot;)
  
      bot.chat(toSend)
      sending = true
      msg.channel.send(`${msg.author.tag} just sent ${toSend}`)
  
      setTimeout(() =&gt; {
        sending = false
        msg.channel.send(chatData.join(&quot;\n&quot;))
        chatData = []
      })
  
    }
  })
  
  bot.on(&quot;message&quot;, message =&gt; {
    let channel = client.channels.cache.get(&quot;id discord channel&quot;)
    if (!channel) return;
    channel.send(`- ${message}`)
  })
  
  client.login(&quot;token&quot;)```
  </code></pre>