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

View File

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

View File

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

View File

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