summaryrefslogtreecommitdiff
path: root/bot.js
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-10-12 14:19:03 -0700
committerFuwn <[email protected]>2021-10-12 14:19:03 -0700
commitacfed16526cf6265cf3a2fd8373535bdba40a8cb (patch)
tree134902df8ea42995b8256bbbd026dc8c3048e546 /bot.js
parentfix: force node version (diff)
downloadbot-main.tar.xz
bot-main.zip
new new newHEADmain
Diffstat (limited to 'bot.js')
-rw-r--r--bot.js120
1 files changed, 87 insertions, 33 deletions
diff --git a/bot.js b/bot.js
index 20c8ec5..4878e01 100644
--- a/bot.js
+++ b/bot.js
@@ -1,9 +1,18 @@
const { REST } = require("@discordjs/rest");
const { Routes } = require("discord-api-types/v9");
const Discord = require("discord.js");
+const ytdl = require("ytdl-core");
+const {
+ joinVoiceChannel,
+ createAudioPlayer,
+ StreamType,
+ AudioPlayerStatus,
+ VoiceConnectionStatus, entersState, createAudioResource,
+} = require("@discordjs/voice");
+const { createDiscordJSAdapter } = require("./adapter");
-const client = new Discord.Client({ intents: [Discord.Intents.FLAGS.GUILDS] });
-const commands = [
+const PREFIX = "//";
+const COMMANDS = [
{
name: "apply",
description: "Replies with the application link for yucky! aiming."
@@ -33,9 +42,41 @@ const commands = [
description: "Replies with the link to yucky! aimings press pack."
},
];
+
+const player = createAudioPlayer();
+const client = new Discord.Client(
+ {
+ intents: [
+ Discord.Intents.FLAGS.GUILDS,
+ Discord.Intents.FLAGS.GUILD_MESSAGES,
+ Discord.Intents.FLAGS.GUILD_VOICE_STATES,
+ ],
+ }
+);
const rest = new REST({ version: "9" })
.setToken("ODg5NDE0MDUzNjE1Nzk2Mjg3.YUg5Yg.2i3KiNfOXC2AbuBg-8jM3InxmuI");
+const connectToChannel = async (channel) => {
+ const connection = joinVoiceChannel({
+ channelId: channel.id,
+ guildId: channel.guild.id,
+ adapterCreator: createDiscordJSAdapter(channel),
+ });
+
+ try {
+ await entersState(connection, VoiceConnectionStatus.Ready, 30e3);
+
+ return connection;
+ } catch (error) { connection.destroy(); throw error; }
+};
+const playURL = url => {
+ const resource = createAudioResource(url, { inputType: StreamType.Arbitrary });
+
+ player.play(resource);
+
+ return entersState(player, AudioPlayerStatus.Playing, 5e3);
+}
+
(async () => {
try {
console.log("started resfreshing application (/) commands.");
@@ -45,7 +86,7 @@ const rest = new REST({ version: "9" })
"889414053615796287",
"888524070432423957"
),
- { body: commands },
+ { body: COMMANDS },
);
console.log("successfully reloaded application (/) commands.");
@@ -90,35 +131,48 @@ client.on("interactionCreate", async interaction => {
}
});
-// client.on("messageCreate", async message => {
-// let arguments;
-// let command;
-//
-// console.log(message);
-//
-// if (message.content.startsWith(">")) {
-// arguments = message.content.slice(">".length).split(/ +/);
-// command = arguments.shift().toLowerCase();
-//
-// console.log(arguments);
-// console.log(command);
-// } else {
-// return;
-// }
-//
-// switch (message) {
-// case "say": {
-// if (message.author.id === "217348698294714370") {
-// await message.delete();
-//
-// message.channel.startTyping();
-//
-// message.channel.send(arguments.join(" "));
-//
-// return message.channel.stopTyping();
-// }
-// } break;
-// }
-// });
+client.on("messageCreate", async message => {
+ let arguments;
+ let command;
+
+ if (message.author.id === client.user.id) { return; }
+
+ if (message.content.startsWith(PREFIX)) {
+ arguments = message.content.slice(PREFIX.length).split(/ +/);
+ command = arguments.shift().toLowerCase();
+ } else {
+ return;
+ }
+
+ switch (command) {
+ case "say": {
+ await message.delete();
+
+ if (message.author.id === "217348698294714370") {
+ await message.channel.send(arguments.join(" "));
+ }
+ } break;
+
+ case "join": {
+ await message.delete();
+
+ if (message.author.id === "217348698294714370") {
+ const connection = await connectToChannel(message.member.voice.channel);
+ }
+ } break;
+
+ case "play": {
+ await message.delete();
+
+ if (message.author.id === "217348698294714370") {
+ const connection = await connectToChannel(message.member.voice.channel);
+
+ await playURL("https://www.soundjay.com/human/fart-01.mp3");
+
+ connection.subscribe(player);
+ }
+ } break;
+ }
+});
client.login("ODg5NDE0MDUzNjE1Nzk2Mjg3.YUg5Yg.2i3KiNfOXC2AbuBg-8jM3InxmuI");