Discord bot image randomizer not functioning

I’m having trouble with my Discord bot’s random image feature. It’s not working as expected. I’ve tried tweaking it but no luck. Interestingly, it works fine with a single image. Here’s what I’ve got:

module.exports = {
  execute(bot, msg, args) {
    const picPool = [
      './neko/nk1.png',
      './neko/nk2.png',
      './neko/nk3.png',
      './neko/nk4.png'
    ];
    const chosenPic = picPool[Math.floor(Math.random() * picPool.length)];
    msg.channel.send('meow', chosenPic);
  }
};

Any ideas what might be going wrong? I’m stumped!

hav u checked if the bot has permission to send files? sometimes that’s the issue. also, try using Discord.MessageAttachment instead of just sending the file path. like this:

const attachment = new Discord.MessageAttachment(chosenPic);
msg.channel.send({ content: ‘meow’, files: [attachment] });

might help! lmk if it works

Hey there! I’ve run into similar issues with Discord bots before. One thing that might be causing trouble is how you’re sending the image. Instead of passing the file path directly to msg.channel.send(), try using the MessageAttachment class from discord.js. Here’s a quick example:

const { MessageAttachment } = require('discord.js');

// ... rest of your code ...

const attachment = new MessageAttachment(chosenPic);
msg.channel.send({ content: 'meow', files: [attachment] });

This approach explicitly tells Discord you’re sending a file attachment. Also, double-check that your file paths are correct and that the bot has permissions to send files in that channel. If you’re still having issues, try logging the chosenPic variable to make sure it’s selecting images correctly. Hope this helps!

Have you considered using the Discord.js v13 or newer? The way you’re sending images is outdated. Try this approach:

const { MessageAttachment } = require('discord.js');

module.exports = {
  execute(bot, msg, args) {
    const picPool = [
      './neko/nk1.png',
      './neko/nk2.png',
      './neko/nk3.png',
      './neko/nk4.png'
    ];
    const chosenPic = picPool[Math.floor(Math.random() * picPool.length)];
    const attachment = new MessageAttachment(chosenPic);
    
    msg.channel.send({ content: 'meow', files: [attachment] })
      .catch(error => console.error('Error sending image:', error));
  }
};

This should resolve your issue. Make sure your bot has the correct permissions and that the file paths are accurate. If problems persist, try logging the chosenPic variable to ensure it’s selecting images correctly.