welcome role / feedback command

This commit is contained in:
Oleksandr Honcharov 2024-06-06 04:07:44 +03:00
parent 4f43b65bd7
commit 934e6493c9
5 changed files with 105 additions and 63 deletions

52
src/commands/feedback.ts Normal file
View File

@ -0,0 +1,52 @@
import { Discord, Slash, SlashChoice, SlashOption } from 'discordx'
import {
ApplicationCommandOptionType,
CommandInteraction,
EmbedBuilder,
} from 'discord.js'
import { db, DBTableEnum } from '../db.ts'
@Discord()
export class Feedback {
@Slash({
name: 'feedback',
description: 'Leave a feedback',
})
async feedback(
@SlashChoice('⭐', '⭐⭐', '⭐⭐⭐', '⭐⭐⭐⭐', '⭐⭐⭐⭐⭐')
@SlashOption({
name: 'rating',
description: 'Leave you review',
required: true,
type: ApplicationCommandOptionType.String,
})
rating: string,
@SlashOption({
name: 'description',
description: 'Leave a description about job',
required: true,
type: ApplicationCommandOptionType.String,
})
description: string,
interaction: CommandInteraction,
) {
const reviewChannelID = await db.get(DBTableEnum.FEEDBACK_CHANNEL)
const embed = new EmbedBuilder()
.setTitle(`⭐ Review by ${interaction.user.username}`)
.setDescription(`Author: <@${interaction.user.id}>`)
.setThumbnail(interaction.user.avatarURL())
.setFields([
{ name: 'Evaluation of support work:', value: rating },
{ name: 'Commentary:', value: '```' + description + '```' },
])
const channel = await interaction.guild?.channels.fetch(reviewChannelID)
if (channel?.isTextBased()) {
channel.send({ embeds: [embed] })
}
await interaction.reply({ ephemeral: true, content: 'Review sent!' })
}
}

View File

@ -2,6 +2,7 @@ import { Discord, Slash, SlashOption } from 'discordx'
import { import {
ApplicationCommandOptionType, ApplicationCommandOptionType,
CommandInteraction, CommandInteraction,
Role,
TextChannel, TextChannel,
} from 'discord.js' } from 'discord.js'
import { db, DBTableEnum } from '../db.ts' import { db, DBTableEnum } from '../db.ts'
@ -17,9 +18,17 @@ export class SetWelcomeChannel {
required: true, required: true,
}) })
channel: TextChannel, channel: TextChannel,
@SlashOption({
name: 'role',
description: 'Role which will be given to user',
type: ApplicationCommandOptionType.Role,
required: true,
})
role: Role,
interaction: CommandInteraction, interaction: CommandInteraction,
) { ) {
await db.set(DBTableEnum.WELCOME_CHANNEL, channel.id) await db.set(DBTableEnum.WELCOME_CHANNEL, channel.id)
await db.set(DBTableEnum.WELCOME_ROLE, role.id)
await interaction.reply({ ephemeral: true, content: 'Success.' }) await interaction.reply({ ephemeral: true, content: 'Success.' })
} }
} }

View File

@ -3,6 +3,7 @@ export const db = new QuickDB()
export enum DBTableEnum { export enum DBTableEnum {
WELCOME_CHANNEL = 'WELCOME_CHANNEL', WELCOME_CHANNEL = 'WELCOME_CHANNEL',
WELCOME_ROLE = 'WELCOME_ROLE',
TICKET_CHANNEL = 'TICKET_CHANNEL', TICKET_CHANNEL = 'TICKET_CHANNEL',
FEEDBACK_CHANNEL = 'FEEDBACK_CHANNEL', FEEDBACK_CHANNEL = 'FEEDBACK_CHANNEL',
PORTFOLIO_CHANNEL = 'PORTFOLIO_CHANNEL', PORTFOLIO_CHANNEL = 'PORTFOLIO_CHANNEL',

View File

@ -1,5 +1,5 @@
import { ArgsOf, Discord, On } from 'discordx' import { ArgsOf, Discord, On } from 'discordx'
import { EmbedBuilder } from 'discord.js' import { EmbedBuilder, channelMention, userMention } from 'discord.js'
import { db, DBTableEnum } from '../db.ts' import { db, DBTableEnum } from '../db.ts'
@Discord() @Discord()
@ -13,23 +13,28 @@ export class GuildMemberAdd {
const welcomeChannelID = await db.get(DBTableEnum.WELCOME_CHANNEL) const welcomeChannelID = await db.get(DBTableEnum.WELCOME_CHANNEL)
const imageURL = await db.get(DBTableEnum.BANNER_URL) const imageURL = await db.get(DBTableEnum.BANNER_URL)
const roleID = await db.get(DBTableEnum.WELCOME_ROLE)
let embed = new EmbedBuilder() let embed = new EmbedBuilder()
.setTitle( .setTitle(
`I'm glad to see you on my server. Let me give you a little tour.`, `I'm glad to see you on my server. Let me give you a little tour.`,
) )
.setDescription( .setDescription(
`> 1. In the https://discord.com/channels/1248048650886578247/${portfolioChannelID} - you can see my previous works. `> 1. In the ${channelMention(portfolioChannelID)} - you can see my previous works.
> 2. Here https://discord.com/channels/1248048650886578247/${makeAnOrderChannelID} you might open a ticket.`, > 2. Here ${channelMention(makeAnOrderChannelID)} you might open a ticket.`,
) )
.setImage(imageURL) .setImage(imageURL)
const channel = await member.guild.channels.fetch(welcomeChannelID) const channel = await member.guild.channels.fetch(welcomeChannelID)
const role = await member.guild.roles.fetch(roleID)
if (channel?.isTextBased()) { if (channel?.isTextBased() && role) {
channel.send({ channel.send({
embeds: [embed], embeds: [embed],
content: `What's up, <@${member.id}>`, content: `What's up, ${userMention(member.id)}`,
}) })
await member.roles.add(role)
} }
} }
} }

View File

@ -1,73 +1,48 @@
import { dirname, importx } from "@discordx/importer"; import { dirname, importx } from '@discordx/importer'
import type { Interaction, Message } from "discord.js"; import type { Interaction, Message } from 'discord.js'
import { IntentsBitField } from "discord.js"; import { IntentsBitField } from 'discord.js'
import { Client } from "discordx"; import { Client } from 'discordx'
import 'dotenv/config' import 'dotenv/config'
export const bot = new Client({ export const bot = new Client({
// To use only guild command intents: [
// botGuilds: [(client) => client.guilds.cache.map((guild) => guild.id)], IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.GuildMessageReactions,
IntentsBitField.Flags.GuildVoiceStates,
IntentsBitField.Flags.MessageContent,
],
// Discord intents silent: false,
intents: [
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.GuildMessageReactions,
IntentsBitField.Flags.GuildVoiceStates,
IntentsBitField.Flags.MessageContent,
],
// Debug logs are disabled in silent mode simpleCommand: {
silent: false, prefix: '!',
},
})
// Configuration for @SimpleCommand bot.once('ready', async () => {
simpleCommand: { await bot.initApplicationCommands()
prefix: "!",
},
});
bot.once("ready", async () => { console.log('Bot started')
// Make sure all guilds are cached })
// await bot.guilds.fetch();
// Synchronize applications commands with Discord bot.on('interactionCreate', (interaction: Interaction) => {
await bot.initApplicationCommands(); bot.executeInteraction(interaction)
})
// To clear all guild commands, uncomment this line, bot.on('messageCreate', async (message: Message) => {
// This is useful when moving from guild commands to global commands await bot.executeCommand(message)
// It must only be executed once })
//
// await bot.clearApplicationCommands(
// ...bot.guilds.cache.map((g) => g.id)
// );
console.log("Bot started");
});
bot.on("interactionCreate", (interaction: Interaction) => {
bot.executeInteraction(interaction);
});
bot.on("messageCreate", async (message: Message) => {
await bot.executeCommand(message);
});
async function run() { async function run() {
// The following syntax should be used in the commonjs environment await importx(`${dirname(import.meta.url)}/{events,commands}/**/*.{ts,js}`)
//
// await importx(__dirname + "/{events,commands}/**/*.{ts,js}");
// The following syntax should be used in the ECMAScript environment if (!process.env.BOT_TOKEN) {
await importx(`${dirname(import.meta.url)}/{events,commands}/**/*.{ts,js}`); throw Error('Could not find BOT_TOKEN in your environment')
}
// Let's start the bot await bot.login(process.env.BOT_TOKEN)
if (!process.env.BOT_TOKEN) {
throw Error("Could not find BOT_TOKEN in your environment");
}
// Log in with your bot token
await bot.login(process.env.BOT_TOKEN);
} }
void run(); void run()