Advertisement
Pychol

Audit Log

Feb 26th, 2021
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. client.on('messageDelete', async (message) => {
  2. const logs = message.guild.channels.find(channel => channel.name === "logs");
  3. if (message.guild.me.hasPermission('MANAGE_CHANNELS') && !logs) {
  4. message.guild.createChannel('logs', 'text');
  5. }
  6. if (!message.guild.me.hasPermission('MANAGE_CHANNELS') && !logs) {
  7. console.log('The logs channel does not exist and tried to create the channel but I am lacking permissions')
  8. }
  9. const entry = await message.guild.fetchAuditLogs({type: 'MESSAGE_DELETE'}).then(audit => audit.entries.first())
  10. let user = ""
  11. if (entry.extra.channel.id === message.channel.id
  12. && (entry.target.id === message.author.id)
  13. && (entry.createdTimestamp > (Date.now() - 5000))
  14. && (entry.extra.count >= 1)) {
  15. user = entry.executor.username
  16. } else {
  17. user = message.author.username
  18. }
  19. logs.send(`A message was deleted in ${message.channel.name} by ${user}`);
  20. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement