Refactoring - v4.0.0
This commit is contained in:
+3
-1
@@ -1,4 +1,6 @@
|
|||||||
src
|
.idea
|
||||||
node_modules
|
node_modules
|
||||||
|
dist
|
||||||
|
src
|
||||||
tsconfig.json
|
tsconfig.json
|
||||||
tsup.config.ts
|
tsup.config.ts
|
||||||
@@ -1,15 +1,11 @@
|
|||||||
const { getVoiceConnection } = require("@discordjs/voice");
|
const {getVoiceConnection} = require("@discordjs/voice");
|
||||||
|
|
||||||
import {maxListenerMethodOptions} from "../Utils/Options/MaxListenerMethodOptions";
|
import {maxListenerMethodOptions} from "../Utils/Options/MaxListenerMethodOptions";
|
||||||
|
|
||||||
export function setMaxAudioListeners({
|
export function setMaxAudioListeners({
|
||||||
GuildID,
|
GuildID,
|
||||||
MaxListeners
|
MaxListeners
|
||||||
}: maxListenerMethodOptions) {
|
}: maxListenerMethodOptions) {
|
||||||
try {
|
let audioConnection = getVoiceConnection(GuildID);
|
||||||
let audioConnection = getVoiceConnection(GuildID);
|
audioConnection.setMaxListeners(MaxListeners);
|
||||||
audioConnection.setMaxListeners(MaxListeners);
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+36
-40
@@ -1,51 +1,47 @@
|
|||||||
const { joinVoiceChannel, createAudioPlayer, createAudioResource } = require("@discordjs/voice");
|
const {joinVoiceChannel, createAudioPlayer, createAudioResource} = require("@discordjs/voice");
|
||||||
const { join } = require("node:path");
|
const {join} = require("node:path");
|
||||||
|
|
||||||
import {startMethodOptions} from "../Utils/Options/StartMethodOptions";
|
import {startMethodOptions} from "../Utils/Options/StartMethodOptions";
|
||||||
|
|
||||||
export function startAudio({
|
export function startAudio({
|
||||||
VoiceChannelID,
|
VoiceChannelID,
|
||||||
GuildID,
|
GuildID,
|
||||||
VoiceAdapter,
|
VoiceAdapter,
|
||||||
ResourceType,
|
ResourceType,
|
||||||
Resource
|
Resource
|
||||||
}: startMethodOptions) {
|
}: startMethodOptions) {
|
||||||
try {
|
let audioPlayer = createAudioPlayer();
|
||||||
const AudioPlayer = createAudioPlayer();
|
|
||||||
|
|
||||||
function streamFile(file: string) {
|
function streamFile(file: string) {
|
||||||
let audioResource = createAudioResource(join(__dirname, file), { inlineVolume: true });
|
let audioResource = createAudioResource(join(__dirname, file), {inlineVolume: true});
|
||||||
AudioPlayer.play(audioResource);
|
audioPlayer.play(audioResource);
|
||||||
|
|
||||||
joinVoiceChannel({
|
joinVoiceChannel({
|
||||||
channelId: VoiceChannelID,
|
channelId: VoiceChannelID,
|
||||||
guildId: GuildID,
|
guildId: GuildID,
|
||||||
adapterCreator: VoiceAdapter
|
adapterCreator: VoiceAdapter
|
||||||
}).subscribe(AudioPlayer);
|
}).subscribe(audioPlayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
function streamLink(link: string) {
|
function streamLink(link: string) {
|
||||||
let audioResource = createAudioResource(link);
|
let audioResource = createAudioResource(link);
|
||||||
AudioPlayer.play(audioResource);
|
audioPlayer.play(audioResource);
|
||||||
|
|
||||||
joinVoiceChannel({
|
joinVoiceChannel({
|
||||||
channelId: VoiceChannelID,
|
channelId: VoiceChannelID,
|
||||||
guildId: GuildID,
|
guildId: GuildID,
|
||||||
adapterCreator: VoiceAdapter
|
adapterCreator: VoiceAdapter
|
||||||
}).subscribe(AudioPlayer)
|
}).subscribe(audioPlayer)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (ResourceType) {
|
switch (ResourceType) {
|
||||||
case "Link":
|
case "Link":
|
||||||
streamLink(Resource);
|
streamLink(Resource);
|
||||||
break;
|
break;
|
||||||
case "File":
|
case "File":
|
||||||
streamFile(Resource);
|
streamFile(Resource);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new TypeError("Audio type isn't valid.");
|
throw new TypeError("Invalid audio type");
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,10 @@
|
|||||||
const { getVoiceConnection } = require("@discordjs/voice");
|
const {getVoiceConnection} = require("@discordjs/voice");
|
||||||
|
|
||||||
import {stopMethodOptions} from "../Utils/Options/StopMethodOptions";
|
import {stopMethodOptions} from "../Utils/Options/StopMethodOptions";
|
||||||
|
|
||||||
export function stopAudio({
|
export function stopAudio({
|
||||||
GuildID
|
GuildID
|
||||||
}: stopMethodOptions) {
|
}: stopMethodOptions) {
|
||||||
try {
|
let audioConnection = getVoiceConnection(GuildID);
|
||||||
let audioConnection = getVoiceConnection(GuildID);
|
audioConnection.destroy();
|
||||||
audioConnection.destroy();
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user