PEPPERBOT VOICE CHAT CAPABILITY

This commit is contained in:
ayeuhugyu 2023-09-27 20:31:22 -07:00
parent 7d5d32fec1
commit b92fe05718
11 changed files with 265 additions and 50 deletions

View file

@ -1,8 +1,8 @@
export default {
name: "openpepper",
name: "git",
description: "posts open pepper repo",
arguments: "none",
execute(message, args) {
message.reply("https://git.reidlab.online/ayeuhugyu/OpenPepper");
message.reply("https://git.reidlab.online/ayeuhugyu/PepperBot");
},
};

26
src/commands/joinvc.js Normal file
View file

@ -0,0 +1,26 @@
import { joinVoiceChannel } from "@discordjs/voice";
import * as dotenv from "dotenv";
dotenv.config();
const guildId = process.env.GUILD_ID;
export default {
name: "joinvc",
description: "joins the vc that the user is currently in",
arguments: "none",
execute(message, args) {
if (message.member.voice.channel) {
let voiceState = message.member.voice;
let connection = joinVoiceChannel({
channelId: voiceState.channelId,
guildId: voiceState.guild.id,
adapterCreator: voiceState.guild.voiceAdapterCreator,
});
message.reply(`connected to <#${voiceState.channelId}>`);
} else {
message.reply("u aint connected to a voice channel blud 😂😂😂");
}
},
};

16
src/commands/leavevc.js Normal file
View file

@ -0,0 +1,16 @@
import { getVoiceConnection } from "@discordjs/voice";
export default {
name: "leavevc",
description: "leaves vc that user is currently in",
arguments: "none",
execute(message, args) {
if (getVoiceConnection(message.guild.id)) {
const connection = getVoiceConnection(message.guild.id);
connection.destroy();
message.reply(`left voice channel <#${connection.joinConfig.channelId}>`);
} else {
message.reply("im not connected to a voice channel here mf");
}
},
};

103
src/commands/soundboard.js Normal file
View file

@ -0,0 +1,103 @@
import {
createAudioPlayer,
createAudioResource,
getVoiceConnection,
joinVoiceChannel,
} from "@discordjs/voice";
import fs from "fs";
import * as dotenv from "dotenv";
dotenv.config();
const prefix = process.env.PREFIX;
export default {
name: "soundboard",
description: "plays specified sound file",
arguments: "file",
execute(message, args) {
const audioPlayer = createAudioPlayer();
let proposedfilename = message.content.slice(
prefix.length + this.name.length + 1
);
const files = fs.readdirSync("resources/soundboard");
let file;
let lsmode = false;
let stopmode = false;
let possibleFilenames = {
regular: proposedfilename,
spaced: proposedfilename.replaceAll(" ", "_"),
spacedmp3: proposedfilename.replaceAll(" ", "_") + ".mp3",
mp3: proposedfilename + ".mp3",
spacedogg: proposedfilename.replaceAll(" ", "_") + ".ogg",
ogg: proposedfilename + ".ogg",
spacedwav: proposedfilename.replaceAll(" ", "_") + ".wav",
wav: proposedfilename + ".wav",
spacedwebm: proposedfilename.replaceAll(" ", "_") + ".webm",
webm: proposedfilename + ".webm",
};
for (const value of Object.values(possibleFilenames)) {
if (files.includes(value)) {
file = value;
}
}
if (proposedfilename === "ls") {
fs.writeFileSync("resources/soundboard/ls.txt", "");
lsmode = true;
for (let file = 0; file < files.length; file++) {
if (files[file] !== "ls.txt") {
fs.appendFileSync("resources/soundboard/ls.txt", `${files[file]}\n`);
}
}
}
if (proposedfilename === "stop") {
let connection = getVoiceConnection(message.guild.id);
connection.subscribe(audioPlayer);
audioPlayer.stop();
message.reply("stopped audio playback");
return;
}
if (!file && !lsmode && !stopmode) {
message.reply(
"unable to find your file in the soundboard folder put `ls` as your args to upload a file of all names. try replacing spaces with _s. you proposed: " +
proposedfilename
);
}
if (!lsmode) {
const audioResource = createAudioResource(`resources/soundboard/${file}`);
let connection = getVoiceConnection(message.guild.id);
if (!connection) {
if (message.member.voice.channel) {
let voiceState = message.member.voice;
let connection = joinVoiceChannel({
channelId: voiceState.channelId,
guildId: voiceState.guild.id,
adapterCreator: voiceState.guild.voiceAdapterCreator,
});
message.reply(`connected to <#${voiceState.channelId}>`);
} else {
message.reply(
"the bot is not in a voice channel so a sound cannot be played, and you are not in a voice channel so it can't auto join. IDIOT!"
);
return;
}
}
connection = getVoiceConnection(message.guild.id);
connection.subscribe(audioPlayer);
audioPlayer.play(audioResource);
} else {
message.channel.send({
files: [
{
attachment: "resources/soundboard/ls.txt",
name: "ls.txt",
},
],
});
}
},
};

View file

@ -2,12 +2,14 @@ import { default as guildMemberAdd } from "./guildMemberAdd.js";
import { default as messageCreate } from "./messageCreate.js";
import { default as messageDelete } from "./messageDelete.js";
import { default as ready } from "./ready.js";
import { default as interactionCreate } from "./interactionCreate.js";
const events = {
guildMemberAdd,
messageCreate,
messageDelete,
ready,
interactionCreate,
};
export default events;

View file

@ -0,0 +1,3 @@
export default function (interaction) {
interaction.reply("stop fucking interacting");
}

View file

@ -1,5 +1,6 @@
import { GatewayIntentBits, Partials, Client } from "discord.js";
import events from "./events/importEvents.js";
import register from "./register-commands.js";
const client = new Client({
intents: [
@ -8,6 +9,7 @@ const client = new Client({
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.GuildVoiceStates,
],
partials: [Partials.Message, Partials.Channel],
});
@ -28,4 +30,10 @@ client.on("messageCreate", async (message) => {
events.messageCreate(message, client);
});
client.on("interactionCreate", (interaction) => {
events.interactionCreate(interaction);
});
register();
client.login(process.env.TOKEN);

View file

@ -1,52 +1,48 @@
require('dotenv').config();
const { REST, Routes, ApplicationCommandOptionType } = require('discord.js');
import dotenv from "dotenv";
import fs from "fs";
dotenv.config();
import {
REST,
Routes,
ApplicationCommandOptionType,
SlashCommandBuilder,
} from "discord.js";
export const commands = [
{
name: 'say',
description: 'forces bot to say message',
options: [
{
name: 'message',
description: 'the message',
type: ApplicationCommandOptionType.String,
required: true
}
]
},
{
name: 'administer',
description: 'administer.',
options: [
{
name: 'password',
description: 'the protections.',
type: ApplicationCommandOptionType.String,
required: true
}
]
},
{
name: 'commands',
description: 'sends a command list',
},
{
name: 'test',
description: 'test command',
},
];
let commands = [];
const rest = new REST({ version: '10' }).setToken(process.env.TOKEN);
const commandFiles = fs
.readdirSync("src/commands/")
.filter((file) => file.endsWith(".js"));
(async () => {
try {
await rest.put(
Routes.applicationGuildCommands(process.env.CLIENT_ID, process.env.GUILD_ID),
{ body: commands }
)
console.log("slash commands registered")
} catch (error) {
console.log(error);
async () => {
for (const file of commandFiles) {
const command = await import(`./commands/${file}`);
commands.push(
`
{
name: "${command.name}",
description: "${command.description}"
}
})();
`.toJSON()
);
}
};
console.log(commands);
const rest = new REST().setToken(process.env.TOKEN);
export default async () => {
try {
await rest.put(
Routes.applicationGuildCommands(
process.env.CLIENT_ID,
process.env.GUILD_ID
),
{ body: commands }
);
console.log("slash commands registered");
} catch (error) {
console.log(error);
}
};