Skip to content

Commit

Permalink
Merge pull request #691 from AikooNee/main
Browse files Browse the repository at this point in the history
Add checks before creating invite link
  • Loading branch information
LucasB25 authored Aug 20, 2024
2 parents e6d3e3f + a6acfb0 commit 7e92626
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Lavalink/example.application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ lavalink:
plugins:
- dependency: "com.github.appujet:jiosaavn-plugin:0.1.7"
repository: "https://jitpack.io"
- dependency: "com.dunctebot:skybot-lavalink-plugin:1.7.0"
- dependency: "com.dunctebot:skybot-lavalink-plugin:1.7.1"
snapshot: false # set to true if you want to use snapshot builds.
- dependency: "com.github.topi314.lavasearch:lavasearch-plugin:1.0.0"
snapshot: false # set to true if you want to use snapshot builds.
Expand Down
49 changes: 29 additions & 20 deletions src/commands/dev/CreateInvite.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { ChannelType } from "discord.js";
import { Command, type Context, type Lavamusic } from "../../structures/index.js";
import { ChannelType, PermissionFlagsBits, type TextChannel } from "discord.js";

export default class CreateInvite extends Command {
constructor(client: Lavamusic) {
super(client, {
name: "createinvite",
description: {
content: "Create a invite link for a guild",
content: "Create an invite link for a guild",
examples: ["createinvite 0000000000000000000"],
usage: "createinvite <guildId>",
},
category: "dev",
aliases: ["ci"],
aliases: ["ci", "gi", "ginvite", "guildinvite"],
cooldown: 3,
args: true,
player: {
Expand All @@ -22,7 +22,7 @@ export default class CreateInvite extends Command {
},
permissions: {
dev: true,
client: ["SendMessages", "CreateInstantInvite", "ReadMessageHistory", "ViewChannel"],
client: ["SendMessages", "CreateInstantInvite", "ReadMessageHistory", "EmbedLinks", "ViewChannel"],
user: [],
},
slashCommand: false,
Expand All @@ -32,30 +32,39 @@ export default class CreateInvite extends Command {

public async run(client: Lavamusic, ctx: Context, args: string[]): Promise<any> {
const guildId = args[0];

const guild = client.guilds.cache.get(guildId);

if (!guild) {
return await ctx.sendMessage("Guild not found.");
return await ctx.sendMessage({
embeds: [this.client.embed().setColor(this.client.color.red).setDescription("Guild not found")],
});
}

try {
const textChannel = guild.channels.cache.find((channel) => channel.type === ChannelType.GuildText);
const textChannel = guild.channels.cache.find(
(c) =>
c.type === ChannelType.GuildText &&
c
.permissionsFor(guild.members.me!)
?.has([PermissionFlagsBits.CreateInstantInvite, PermissionFlagsBits.SendMessages, PermissionFlagsBits.ViewChannel]),
) as TextChannel;

if (!textChannel) {
return await ctx.sendMessage("No text channel found in the guild.");
}

const invite = await textChannel.createInvite({
maxUses: 0,
maxAge: 0,
if (!textChannel) {
return await ctx.sendMessage({
embeds: [this.client.embed().setColor(this.client.color.red).setDescription("No suitable channel found")],
});

await ctx.author.send(`Guild: ${guild.name}\nInvite Link: ${invite.url}`);
await ctx.sendMessage("Invite link has been sent to your DM.");
} catch (_error) {
await ctx.sendMessage("Failed to create invite link.");
}

const invite = await textChannel.createInvite({
maxAge: 3600, // 1 hour
maxUses: 1,
reason: `Requested by my admin: ${ctx.author.username}`,
});

return await ctx.sendMessage({
embeds: [
this.client.embed().setColor(this.client.color.main).setDescription(`Invite link for ${guild.name}: [Link](${invite.url})`),
],
});
}
}

Expand Down

0 comments on commit 7e92626

Please sign in to comment.