Files
quarksBot/commands/set-channel.js
T
2022-07-05 18:29:47 -07:00

81 lines
2.8 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: "channel",
description: "Channel to send 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);
let channelSetting, query;
if (channelType == "action") {
channelSetting = guild.server.actionChannel;
query = "server.actionChannel"
} else if (channelType == "tweet") {
channelSetting = guild.server.tweetChannel;
query = "server.tweetChannel"
}
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},{$set:{query: 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 <#${args[0].value}> for ${channelType}.`);
return interaction.send({ embeds: [successEmbed] });
});
},
},
}