montur
montur
DIAdiscord.js - Imagine an app
Created by montur on 2/16/2024 in #djs-questions
how do i play audio with my discord bot?
i have this code
const { SlashCommandBuilder } = require('discord.js');
const { joinVoiceChannel } = require('@discordjs/voice');

module.exports = {
data: new SlashCommandBuilder()
.setName('play')
.setDescription('Plays music'),
async execute(interaction) {
const guild = interaction.guild;
const member = interaction.member;

// Check if the member is in a voice channel
if (member.voice.channel) {
interaction.reply('Joining: ' + member.voice.channel.name);
// The member is in a voice channel
const connection = joinVoiceChannel({
channelId: member.voice.channel.id,
guildId: guild.id,
adapterCreator: guild.voiceAdapterCreator,
});

//use file: './sound/AAAAUUUGHHHH.mp3'

} else {
interaction.reply('You need to be in a voice channel to use this command!');
}
},
};
const { SlashCommandBuilder } = require('discord.js');
const { joinVoiceChannel } = require('@discordjs/voice');

module.exports = {
data: new SlashCommandBuilder()
.setName('play')
.setDescription('Plays music'),
async execute(interaction) {
const guild = interaction.guild;
const member = interaction.member;

// Check if the member is in a voice channel
if (member.voice.channel) {
interaction.reply('Joining: ' + member.voice.channel.name);
// The member is in a voice channel
const connection = joinVoiceChannel({
channelId: member.voice.channel.id,
guildId: guild.id,
adapterCreator: guild.voiceAdapterCreator,
});

//use file: './sound/AAAAUUUGHHHH.mp3'

} else {
interaction.reply('You need to be in a voice channel to use this command!');
}
},
};
and i wanna play the file
'./sound/AAAAUUUGHHHH.mp3'
'./sound/AAAAUUUGHHHH.mp3'
but i have no idea how i could do that please help me out
9 replies
DIAdiscord.js - Imagine an app
Created by montur on 2/15/2024 in #djs-questions
no reliable output and i dont know why:
const { SlashCommandBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('user')
.setDescription('Provides information about the user.'),
async execute(interaction) {
// Fetch fresh data to ensure accuracy
await interaction.member.fetch(true);
// Check if the user is in a voice channel
if (interaction.member.voice.channel) {
await interaction.reply(`You are currently in the voice channel: ${interaction.member.voice.channel.name}`);
} else {
await interaction.reply('You are not currently in a voice channel.');
}
},
};
const { SlashCommandBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('user')
.setDescription('Provides information about the user.'),
async execute(interaction) {
// Fetch fresh data to ensure accuracy
await interaction.member.fetch(true);
// Check if the user is in a voice channel
if (interaction.member.voice.channel) {
await interaction.reply(`You are currently in the voice channel: ${interaction.member.voice.channel.name}`);
} else {
await interaction.reply('You are not currently in a voice channel.');
}
},
};
21 replies