gibigbig
gibigbig
DIAdiscord.js - Imagine an app
Created by gibigbig on 7/10/2023 in #djs-voice
Not hearing audio
Any idea why?
// Load up the discord.js library
const glob = require("glob")
// This is your client. Some people call it `bot`, some people call it `self`,
// some might call it `cootchie`. Either way, when you see `client.something`, or `bot.something`,
// this is what we're refering to. Your client.
const { Client, Collection, GatewayIntentBits, EmbedBuilder, AttachmentBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, Events } = require('discord.js');
const dir = '/home/gibigbig/podcast/podcasts';
const fs = require('fs');
const {
joinVoiceChannel,
createAudioPlayer,
createAudioResource,
entersState,
StreamType,
AudioPlayerStatus,
VoiceConnectionStatus,
} = require('@discordjs/voice');

const player = createAudioPlayer();

player.on(AudioPlayerStatus.Playing, (oldState, newState) => {
console.log('Audio player is in the Playing state!');
});

const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildVoiceStates
]
});


// Here we load the config.json file that contains our token and our prefix values.
const config = require("./config.json");
// config.token contains the bot's token
// config.prefix contains the message prefix.

function shuffle(array) {
for (let i = array.length - 1; i > 0; i--) {
let j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
}

function play(connection, files, count, channel) {
player.play(files[count]);
//const dispatcher = connection.play(files[count]);
console.log(`Playing: ${files[count]}`);
client.user.setActivity(`Playing: ${files[count]}`);
channel.setTopic('♫ Now Playing: "The Art Of Manliness Podcast"')

}

function playSong(files, count) {
console.log(files[count])
const resource = createAudioResource(files[count], {
inputType: StreamType.Arbitrary,
});

player.play(resource);
client.user.setActivity(`Playing: ${files[count]}`);
return entersState(player, AudioPlayerStatus.Playing, 5000);
}


client.on("ready", async () => {
let count = 0
// options is optional
glob(`${dir}/*.mp3`, {}, async (err, files) => {
console.log(files)
shuffle(files)
let channel = await client.channels.cache.get("320802196641808385")

const connection = joinVoiceChannel({
channelId: "320802196641808385",
guildId: "320802196641808384",
adapterCreator: channel.guild.voiceAdapterCreator,
});
playSong(files, count)
});
});




client.login(config.token);
// Load up the discord.js library
const glob = require("glob")
// This is your client. Some people call it `bot`, some people call it `self`,
// some might call it `cootchie`. Either way, when you see `client.something`, or `bot.something`,
// this is what we're refering to. Your client.
const { Client, Collection, GatewayIntentBits, EmbedBuilder, AttachmentBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, Events } = require('discord.js');
const dir = '/home/gibigbig/podcast/podcasts';
const fs = require('fs');
const {
joinVoiceChannel,
createAudioPlayer,
createAudioResource,
entersState,
StreamType,
AudioPlayerStatus,
VoiceConnectionStatus,
} = require('@discordjs/voice');

const player = createAudioPlayer();

player.on(AudioPlayerStatus.Playing, (oldState, newState) => {
console.log('Audio player is in the Playing state!');
});

const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildVoiceStates
]
});


// Here we load the config.json file that contains our token and our prefix values.
const config = require("./config.json");
// config.token contains the bot's token
// config.prefix contains the message prefix.

function shuffle(array) {
for (let i = array.length - 1; i > 0; i--) {
let j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
}

function play(connection, files, count, channel) {
player.play(files[count]);
//const dispatcher = connection.play(files[count]);
console.log(`Playing: ${files[count]}`);
client.user.setActivity(`Playing: ${files[count]}`);
channel.setTopic('♫ Now Playing: "The Art Of Manliness Podcast"')

}

function playSong(files, count) {
console.log(files[count])
const resource = createAudioResource(files[count], {
inputType: StreamType.Arbitrary,
});

player.play(resource);
client.user.setActivity(`Playing: ${files[count]}`);
return entersState(player, AudioPlayerStatus.Playing, 5000);
}


client.on("ready", async () => {
let count = 0
// options is optional
glob(`${dir}/*.mp3`, {}, async (err, files) => {
console.log(files)
shuffle(files)
let channel = await client.channels.cache.get("320802196641808385")

const connection = joinVoiceChannel({
channelId: "320802196641808385",
guildId: "320802196641808384",
adapterCreator: channel.guild.voiceAdapterCreator,
});
playSong(files, count)
});
});




client.login(config.token);
7 replies