tark
tark
DIAdiscord.js - Imagine an app
Created by tark on 2/6/2025 in #djs-questions
Answer on quoted message for slash commands
Hey, I’m working on a bot using Discord.js and I’d like a Slash Command reply to the message that the user is referencing (the quoted message). Use Case: A user replies to a message in the chat. They use the Slash Command in their reply. The bot should not reply to the Slash Command message itself but instead to the original message the user replied to. What I’ve tried: I attempted to use interaction.message.reference.messageId, but it seems this only works with regular messages and not Slash Commands. Is there any way to get the referenced message in a Slash Command? Or is this only possible with Message Commands? Node: v20 djs: 14.15.2
8 replies
DIAdiscord.js - Imagine an app
Created by tark on 5/25/2023 in #djs-voice
Bot joined in channel but is fullmuted, why?
In voice channel my discord bot is fullmuted, so he cant play a sound. Is there a simple fix?
const {
joinVoiceChannel,
createAudioPlayer,
createAudioResource,
entersState,
VoiceConnectionStatus,
} = require('@discordjs/voice');
const ytdl = require('ytdl-core');

async function playSound(bot, message) {
if (message.content.startsWith('!play')) {
const args = message.content.split(' ');
const url = args[1];

const connection = joinVoiceChannel({
channelId: message.member.voice.channelId,
guildId: message.guild.id,
adapterCreator: message.guild.voiceAdapterCreator,
});

if (!message.member.voice.channel) {
message.reply('Du bist in keinem Voicechannel!');
return;
}

try {
await entersState(connection, VoiceConnectionStatus.Signalling, 5e3);

const player = createAudioPlayer();
connection.subscribe(player);

if (url.includes('youtube.com')) {
const resource = createAudioResource(ytdl(url, {filter: 'audioonly'}));
player.play(resource);
} else if (url.includes('soundcloud.com')) {

} else {
message.reply('Der Link ist nicht von Youtube oder Soundcloud!');
}
} catch (error) {
console.error(error);
message.reply('Ein Fehler ist aufgetreten.');
}
}
}

module.exports = {playSound};
const {
joinVoiceChannel,
createAudioPlayer,
createAudioResource,
entersState,
VoiceConnectionStatus,
} = require('@discordjs/voice');
const ytdl = require('ytdl-core');

async function playSound(bot, message) {
if (message.content.startsWith('!play')) {
const args = message.content.split(' ');
const url = args[1];

const connection = joinVoiceChannel({
channelId: message.member.voice.channelId,
guildId: message.guild.id,
adapterCreator: message.guild.voiceAdapterCreator,
});

if (!message.member.voice.channel) {
message.reply('Du bist in keinem Voicechannel!');
return;
}

try {
await entersState(connection, VoiceConnectionStatus.Signalling, 5e3);

const player = createAudioPlayer();
connection.subscribe(player);

if (url.includes('youtube.com')) {
const resource = createAudioResource(ytdl(url, {filter: 'audioonly'}));
player.play(resource);
} else if (url.includes('soundcloud.com')) {

} else {
message.reply('Der Link ist nicht von Youtube oder Soundcloud!');
}
} catch (error) {
console.error(error);
message.reply('Ein Fehler ist aufgetreten.');
}
}
}

module.exports = {playSound};
21 replies