Skip to content

feat: Send message to ticket on member join/leave #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
.env
.env
package-lock.json
16 changes: 16 additions & 0 deletions events/guild/guildMemberAdd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = async(client, member) => {
const fetchAllTickets = await client.db.all("tickets");
const filterUserTickets = fetchAllTickets.filter(r => r.data.user === member.id);
if (!filterUserTickets.length) return;
filterUserTickets.forEach(ticketObj => {
const ticket = member.guild.channels.cache.get(ticketObj.data.ticket);
if (!ticket) return;
await ticket.permissionOverwrites.edit(member, {
VIEW_CHANNEL: true,
SEND_MESSAGES: true
})
ticket.send({
content: `${member} **(${member.user.tag})** has left the server and rejoined, and I automatically add a member to the ticket.`
})
})
}
12 changes: 12 additions & 0 deletions events/guild/guildMemberRemove.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = async(client, member) => {
const fetchAllTickets = await client.db.all("tickets");
const filterUserTickets = fetchAllTickets.filter(r => r.data.user === member.id);
if (!filterUserTickets.length) return;
filterUserTickets.forEach(ticketObj => {
const ticket = member.guild.channels.cache.get(ticketObj.data.ticket);
if (!ticket) return;
ticket.send({
content: `${member} **(${member.user.tag})** has left the server, if you want to delete this ticket you can use \`/delete\` command.`
})
})
}
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const Discord = require('discord.js');
const client = new Discord.Client({ intents: ['GUILDS', 'GUILD_MESSAGES'] });
const client = new Discord.Client({ intents: ['GUILDS', 'GUILD_MESSAGES', 'GUILD_MEMBERS'] });
const mysql = require('mysql-database');
const database = new mysql();
client.commands = new Discord.Collection();
Expand Down
Loading