Skip to content

Commit

Permalink
⚡ Update & migrate to basic Discord.js 14
Browse files Browse the repository at this point in the history
Note: this commit does not incldue slash commands or any new major features, it is simply a migration to the latest stable version
  • Loading branch information
eritislami committed Jan 22, 2023
1 parent 89876f5 commit 6bbd769
Show file tree
Hide file tree
Showing 11 changed files with 372 additions and 294 deletions.
14 changes: 7 additions & 7 deletions commands/help.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Message, MessageEmbed } from "discord.js";
import { Message, EmbedBuilder } from "discord.js";
import { i18n } from "../utils/i18n";
import { bot } from "../index";

Expand All @@ -9,17 +9,17 @@ export default {
execute(message: Message) {
let commands = bot.commands;

let helpEmbed = new MessageEmbed()
let helpEmbed = new EmbedBuilder()
.setTitle(i18n.__mf("help.embedTitle", { botname: message.client.user!.username }))
.setDescription(i18n.__("help.embedDescription"))
.setColor("#F8AA2A");

commands.forEach((cmd) => {
helpEmbed.addField(
`**${bot.prefix}${cmd.name} ${cmd.aliases ? `(${cmd.aliases})` : ""}**`,
`${cmd.description}`,
true
);
helpEmbed.addFields({
name: `**${bot.prefix}${cmd.name} ${cmd.aliases ? `(${cmd.aliases})` : ""}**`,
value: `${cmd.description}`,
inline: true
});
});

helpEmbed.setTimestamp();
Expand Down
8 changes: 4 additions & 4 deletions commands/lyrics.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Message, MessageEmbed } from "discord.js";
import { Message, EmbedBuilder } from "discord.js";
import { i18n } from "../utils/i18n";
// @ts-ignore
import lyricsFinder from "lyrics-finder";
Expand All @@ -23,14 +23,14 @@ export default {
lyrics = i18n.__mf("lyrics.lyricsNotFound", { title: title });
}

let lyricsEmbed = new MessageEmbed()
let lyricsEmbed = new EmbedBuilder()
.setTitle(i18n.__mf("lyrics.embedTitle", { title: title }))
.setDescription(lyrics)
.setColor("#F8AA2A")
.setTimestamp();

if (lyricsEmbed.description!.length >= 2048)
lyricsEmbed.description = `${lyricsEmbed.description!.substr(0, 2045)}...`;
if (lyricsEmbed.data.description!.length >= 2048)
lyricsEmbed.setDescription(`${lyricsEmbed.data.description!.substr(0, 2045)}...`);

return message.reply({ embeds: [lyricsEmbed] }).catch(console.error);
}
Expand Down
18 changes: 9 additions & 9 deletions commands/nowplaying.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Message, MessageEmbed } from "discord.js";
import { Message, EmbedBuilder } from "discord.js";
import { splitBar } from "string-progressbar";
import { i18n } from "../utils/i18n";
import { bot } from "../index";
Expand All @@ -10,28 +10,28 @@ export default {
execute(message: Message) {
const queue = bot.queues.get(message.guild!.id);

if (!queue || !queue.songs.length)
return message.reply(i18n.__("nowplaying.errorNotQueue")).catch(console.error);
if (!queue || !queue.songs.length) return message.reply(i18n.__("nowplaying.errorNotQueue")).catch(console.error);

const song = queue.songs[0];
const seek = queue.resource.playbackDuration / 1000;
const left = song.duration - seek;

let nowPlaying = new MessageEmbed()
let nowPlaying = new EmbedBuilder()
.setTitle(i18n.__("nowplaying.embedTitle"))
.setDescription(`${song.title}\n${song.url}`)
.setColor("#F8AA2A");

if (song.duration > 0) {
nowPlaying.addField(
"\u200b",
new Date(seek * 1000).toISOString().substr(11, 8) +
nowPlaying.addFields({
name: "\u200b",
value:
new Date(seek * 1000).toISOString().substr(11, 8) +
"[" +
splitBar(song.duration == 0 ? seek : song.duration, seek, 20)[0] +
"]" +
(song.duration == 0 ? " ◉ LIVE" : new Date(song.duration * 1000).toISOString().substr(11, 8)),
false
);
inline: false
});

nowPlaying.setFooter({
text: i18n.__mf("nowplaying.timeRemaining", {
Expand Down
17 changes: 8 additions & 9 deletions commands/playlist.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DiscordGatewayAdapterCreator, joinVoiceChannel } from "@discordjs/voice";
import { Message, MessageEmbed } from "discord.js";
import { Message, EmbedBuilder } from "discord.js";
import { bot } from "../index";
import { MusicQueue } from "../structs/MusicQueue";
import { Playlist } from "../structs/Playlist";
Expand Down Expand Up @@ -51,22 +51,21 @@ export default {

bot.queues.set(message.guild!.id, newQueue);
newQueue.songs.push(...playlist.videos);

newQueue.enqueue(playlist.videos[0]);
}

let playlistEmbed = new MessageEmbed()
let playlistEmbed = new EmbedBuilder()
.setTitle(`${playlist.data.title}`)
.setDescription(
playlist.videos.map((song: Song, index: number) => `${index + 1}. ${song.title}`).join("\n")
)
.setDescription(playlist.videos.map((song: Song, index: number) => `${index + 1}. ${song.title}`).join("\n"))
.setURL(playlist.data.url!)
.setColor("#F8AA2A")
.setTimestamp();

if (playlistEmbed.description!.length >= 2048)
playlistEmbed.description =
playlistEmbed.description!.substr(0, 2007) + i18n.__("playlist.playlistCharLimit");
if (playlistEmbed.data.description!.length >= 2048)
playlistEmbed.setDescription(
playlistEmbed.data.description!.substr(0, 2007) + i18n.__("playlist.playlistCharLimit")
);

message
.reply({
Expand Down
8 changes: 3 additions & 5 deletions commands/queue.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Message, MessageEmbed, MessageReaction, User } from "discord.js";
import { Message, EmbedBuilder, MessageReaction, User } from "discord.js";
import { bot } from "../index";
import { Song } from "../structs/Song";
import { i18n } from "../utils/i18n";
Expand Down Expand Up @@ -77,13 +77,11 @@ function generateQueueEmbed(message: Message, songs: Song[]) {

const info = current.map((track) => `${++j} - [${track.title}](${track.url})`).join("\n");

const embed = new MessageEmbed()
const embed = new EmbedBuilder()
.setTitle(i18n.__("queue.embedTitle"))
.setThumbnail(message.guild?.iconURL()!)
.setColor("#F8AA2A")
.setDescription(
i18n.__mf("queue.embedCurrentSong", { title: songs[0].title, url: songs[0].url, info: info })
)
.setDescription(i18n.__mf("queue.embedCurrentSong", { title: songs[0].title, url: songs[0].url, info: info }))
.setTimestamp();
embeds.push(embed);
}
Expand Down
13 changes: 8 additions & 5 deletions commands/search.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Message, MessageEmbed, TextChannel } from "discord.js";
import { Message, EmbedBuilder, TextChannel } from "discord.js";
import youtube from "youtube-sr";
import { bot } from "../index";
import { i18n } from "../utils/i18n";
Expand All @@ -21,7 +21,7 @@ export default {

const search = args.join(" ");

let resultsEmbed = new MessageEmbed()
let resultsEmbed = new EmbedBuilder()
.setTitle(i18n.__("search.resultEmbedTitle"))
.setDescription(i18n.__mf("search.resultEmbedDesc", { search: search }))
.setColor("#F8AA2A");
Expand All @@ -30,7 +30,10 @@ export default {
const results = await youtube.search(search, { limit: 10, type: "video" });

results.map((video, index) =>
resultsEmbed.addField(`https://youtube.com/watch?v=${video.id}`, `${index + 1}. ${video.title}`)
resultsEmbed.addFields({
name: `https://youtube.com/watch?v=${video.id}`,
value: `${index + 1}. ${video.title}`
})
);

let resultsMessage = await message.channel.send({ embeds: [resultsEmbed] });
Expand All @@ -49,10 +52,10 @@ export default {
let songs = reply.split(",").map((str) => str.trim());

for (let song of songs) {
await bot.commands.get("play")!.execute(message, [resultsEmbed.fields[parseInt(song) - 1].name]);
await bot.commands.get("play")!.execute(message, [resultsEmbed.data.fields![parseInt(song) - 1].name]);
}
} else {
const choice: any = resultsEmbed.fields[parseInt(response.first()?.toString()!) - 1].name;
const choice: any = resultsEmbed.data.fields![parseInt(response.first()?.toString()!) - 1].name;
bot.commands.get("play")!.execute(message, [choice]);
}

Expand Down
14 changes: 7 additions & 7 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Client, Intents } from "discord.js";
import { Client, GatewayIntentBits } from "discord.js";
import { Bot } from "./structs/Bot";

export const bot = new Bot(
new Client({
restTimeOffset: 0,
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_VOICE_STATES,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
Intents.FLAGS.DIRECT_MESSAGES
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.MessageContent,
GatewayIntentBits.DirectMessages
]
})
);
Loading

0 comments on commit 6bbd769

Please sign in to comment.