101 lines
3.6 KiB
JavaScript
101 lines
3.6 KiB
JavaScript
const { MessageEmbed } = require('discord.js');
|
|
|
|
module.exports = {
|
|
name: "set-channel",
|
|
description: "set a channel",
|
|
usage: "[channel type] [channel]",
|
|
permissions: {
|
|
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
|
member: ["MANAGE_GUILD"],
|
|
},
|
|
SlashCommand: {
|
|
options: [
|
|
{
|
|
name: "channel-type",
|
|
description: "What the channel is used for",
|
|
value: "channel-type",
|
|
type: 3,
|
|
required: true,
|
|
choices: [
|
|
{ name: "action", value: "action" }, { name: "tweet", value: "tweet" }, { name: "allowed", value: "allowed" },
|
|
],
|
|
},
|
|
{
|
|
name: "channel",
|
|
description: "Channel to send actions/tweets",
|
|
value: "channel",
|
|
type: 7,
|
|
required: true,
|
|
},
|
|
],
|
|
/**
|
|
*
|
|
* @param {require("../structures/QuarksBot")} client
|
|
* @param {import("discord.js").MessageCreate} message
|
|
* @param {string[]} args
|
|
* @param {*} param3
|
|
*/
|
|
run: async (client, interaction, args, { GuildDB }) => {
|
|
if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) {
|
|
return interaction.send(`You are not allowed to use the bot in this channel.`);
|
|
}
|
|
|
|
let channelType = args[0].value;
|
|
let channelid = args[1].value;
|
|
let channel = client.channels.cache.get(channelid);
|
|
|
|
if (!channel) return interaction.send(`Cannot find that channel.`);
|
|
if (channel.type=="voice") return interaction.send(`Connot set voice channel to ${channelType} channel.`);
|
|
if (channel.deleted) return interaction.send(`Connot set deleted channel to ${channelType} channel.`);
|
|
let guild = await client.dbo.collection("guilds").findOne({"server.serverID":interaction.guild.id}).then(guild => guild);
|
|
|
|
if (channelType == "allowed") {
|
|
client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID}, {$push:{"server.allowedChannels": channelid}}, function (err, res) {
|
|
if (err) {
|
|
client.log(err);
|
|
let embed = new MessageEmbed()
|
|
.setTitle(err)
|
|
.setColor("RED")
|
|
|
|
return interaction.send({ embeds: [embed] });
|
|
}
|
|
});
|
|
|
|
let successEmbed = new MessageEmbed()
|
|
.setColor("GREEN")
|
|
.setTitle("Success")
|
|
.setDescription(`Successfully set <#${channelid}> as an allowed channel.`);
|
|
|
|
return interaction.send({ embeds: [successEmbed] });
|
|
}
|
|
|
|
let channelSetting, query;
|
|
if (channelType == "action") {
|
|
channelSetting = guild.server.actionChannel;
|
|
query = { $set: { "server.actionChannel": channelid } }
|
|
} else if (channelType == "tweet") {
|
|
channelSetting = guild.server.tweetChannel;
|
|
query = { $set: { "server.tweetChannel": channelid } }
|
|
}
|
|
|
|
if (channelSetting == channelid) return interaction.send(`The channel <#${args[1].value}> has already been set for ${channelType}s.`);
|
|
client.dbo.collection("guilds").updateOne({"server.serverID":interaction.guild.id},query,function(err, res) {
|
|
if (err) {
|
|
client.log(err);
|
|
let embed = new MessageEmbed()
|
|
.setTitle(err)
|
|
.setColor("RED")
|
|
|
|
return interaction.send({ embeds: [embed] });
|
|
}
|
|
|
|
let successEmbed = new MessageEmbed()
|
|
.setColor("GREEN")
|
|
.setTitle("Success")
|
|
.setDescription(`Successfully set <#${channelid}> for ${channelType}s.`);
|
|
|
|
return interaction.send({ embeds: [successEmbed] });
|
|
});
|
|
},
|
|
},
|
|
} |