Reputation: 13
I'm trying to make a talking ben command for my bot, and it just won't work. I want the bot to send an audio clip as a response whenever someone asks a question, and if they don't specify a question, the bot will send a "ben" sound effect. No response to the command in Discord at all.
Here's the code:
ben.js
:
const Discord = require('discord.js');
const yes = new Discord.MessageAttachment(
'https://soundboardguy.com/sounds/talking-ben-yes_scachnw/',
);
const no = new Discord.MessageAttachment(
'https://soundboardguy.com/sounds/talking-ben-no/',
);
const laugh = new Discord.MessageAttachment(
'https://soundboardguy.com/sounds/talking-ben-laugh/',
);
const uhh = new Discord.MessageAttachment(
'https://www.101soundboards.com/sounds/726466-uhh',
);
const ben = new Discord.MessageAttachment(
'https://www.101soundboards.com/sounds/726450-ben',
);
module.exports = {
name: 'ben',
description: 'talking ben command',
async execute(client, message, args) {
if (!args[0]) return ben;
let benreplies = [yes, no, laugh, uhh];
let result = Math.floor(Math.random() * benreplies.length);
message.channel.send(replies[result]);
},
};
main.js
:
const Discord = require('discord.js');
const client = new Discord.Client({ intents: ['GUILDS', 'GUILD_MESSAGES'] });
const prefix = '.';
const fs = require('fs');
client.commands = new Discord.Collection();
const commandFiles = fs
.readdirSync('./commands/')
.filter((file) => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.once('ready', () => {
console.log('Blueberry bot is online!');
});
client.on('messageCreate', (message) => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ + /);
const command = args.shift().toLowerCase();
// ...
else if (command === 'ben') {
client.commands.get('ben').execute(message, args, Discord);
}
});
Upvotes: 1
Views: 136
Reputation: 1362
The links are incorrect, you used the links that have a user interface, where the user can see the audio, login, see "related" audios etc.. not the actual source audio mp3 file.
For example, that link : https://www.101soundboards.com/sounds/726450-ben
is incorrect. Replace it with https://www.101soundboards.com/storage/board_sounds_rendered/726450.mp3
Do the exact same thing with every file and you're ready to go !
Upvotes: 0
Reputation: 23160
First, you need to make sure that the links to the sound files are valid. You're currently using links pointing to an HTML page, not the mp3 files.
Second, you need to use an object with a files
property to send a file. See the MessageOptions
. files
will also need to be an array. The following will work:
let sounds = [
{
id: 'ben',
link: 'https://soundboardguy.com/wp-content/uploads/2022/03/talking-ben-ben.mp3',
},
{
id: 'laugh',
link: 'https://soundboardguy.com/wp-content/uploads/2022/02/Talking-Ben-Laughing-Sound-Effect-1.mp3',
},
{
id: 'no',
link: 'https://soundboardguy.com/wp-content/uploads/2022/03/Talking-Ben-No-Sound-Effect.mp3',
},
{
id: 'uhh',
link: 'https://soundboardguy.com/wp-content/uploads/2021/06/huh-uhh.mp3',
},
{
id: 'yes',
link: 'https://soundboardguy.com/wp-content/uploads/2022/03/talking-ben-yes_SCacHNW.mp3',
},
];
let randomSound = sounds[Math.floor(Math.random() * sounds.length)];
message.channel.send({
files: [new MessageAttachment(randomSound.link, `${randomSound.id}.mp3`)],
});
Upvotes: 2