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:
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:
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!
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.