Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

226
Visualizações
Sending a random sound file as a response not working

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);
  }
});
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

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`)],
});

enter image description here

about 4 years ago · Juan Pablo Isaza Relatório

0

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 !

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda