bot.js 5.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. var { Client, Attachment, MessageMentions } = require('discord.js');
  2. var bot = new Client()
  3. /*
  4. bot.on('ready', function() {
  5. // console.log('ready', arguments)
  6. console.log('Logged in as %s - %s\n', bot.username, bot.id);
  7. });
  8. */
  9. const EVERYONE_PATTERN = /@(everyone|here)/g
  10. const USERS_PATTERN = /<@!?([0-9]+)>/g
  11. const ROLES_PATTERN = /<@&([0-9]+)>/g
  12. const CHANNELS_PATTERN = /<#([0-9]+)>/g
  13. const stringify = message => `${new Date().toISOString()} #${message.channel.name} @${message.author.username}: ${message.toString()}`
  14. .replace(CHANNELS_PATTERN, ((m,id) => `#${message.mentions.channels.find(x => x.id == id).name}`))
  15. .replace(ROLES_PATTERN, ((m,id) => `[${message.mentions.roles.find(x => x.id == id).name}]`))
  16. .replace(USERS_PATTERN, ((m,id) => `@${message.mentions.users.find(x => x.id == id).username}`))
  17. bot.on('message', function(message) {
  18. console.log(stringify(message))
  19. });
  20. bot.on('messageDelete', function(message) {
  21. console.log(`[MessageDelete] ${stringify(message)}`)
  22. });
  23. bot.on('messageUpdate', function(oldMessage, newMessage) {
  24. console.log(`[MessageUpdate]\nold: ${stringify(oldMessage)}\nnew: ${stringify(newMessage)}`)
  25. })
  26. /*
  27. bot.on('channelCreate', function() { console.log('channelCreate', Array.from(arguments)) })
  28. bot.on('channelDelete', function() { console.log('channelDelete', Array.from(arguments)) })
  29. bot.on('channelPinsUpdate', function() { console.log('channelPinsUpdate', Array.from(arguments)) })
  30. bot.on('channelUpdate', function() { console.log('channelUpdate', Array.from(arguments)) })
  31. bot.on('clientUserGuildSettingsUpdate', function() { console.log('clientUserGuildSettingsUpdate', Array.from(arguments)) })
  32. bot.on('clientUserSettingsUpdate', function() { console.log('clientUserSettingsUpdate', Array.from(arguments)) })
  33. bot.on('debug', function() { console.log('debug', Array.from(arguments)) })
  34. bot.on('disconnect', function() { console.log('disconnect', Array.from(arguments)) })
  35. bot.on('emojiCreate', function() { console.log('emojiCreate', Array.from(arguments)) })
  36. bot.on('emojiDelete', function() { console.log('emojiDelete', Array.from(arguments)) })
  37. bot.on('emojiUpdate', function() { console.log('emojiUpdate', Array.from(arguments)) })
  38. bot.on('error', function() { console.log('error', Array.from(arguments)) })
  39. bot.on('guildBanAdd', function() { console.log('guildBanAdd', Array.from(arguments)) })
  40. bot.on('guildBanRemove', function() { console.log('guildBanRemove', Array.from(arguments)) })
  41. bot.on('guildCreate', function() { console.log('guildCreate', Array.from(arguments)) })
  42. bot.on('guildDelete', function() { console.log('guildDelete', Array.from(arguments)) })
  43. bot.on('guildMemberAdd', function() { console.log('guildMemberAdd', Array.from(arguments)) })
  44. bot.on('guildMemberAvailable', function() { console.log('guildMemberAvailable', Array.from(arguments)) })
  45. bot.on('guildMemberRemove', function() { console.log('guildMemberRemove', Array.from(arguments)) })
  46. bot.on('guildMembersChunk', function() { console.log('guildMembersChunk', Array.from(arguments)) })
  47. bot.on('guildMemberSpeaking', function() { console.log('guildMemberSpeaking', Array.from(arguments)) })
  48. bot.on('guildMemberUpdate', function() { console.log('guildMemberUpdate', Array.from(arguments)) })
  49. bot.on('guildUnavailable', function() { console.log('guildUnavailable', Array.from(arguments)) })
  50. bot.on('guildUpdate', function() { console.log('guildUpdate', Array.from(arguments)) })
  51. bot.on('message', function() { console.log('message', Array.from(arguments)) })
  52. bot.on('messageDelete', function() { console.log('messageDelete', Array.from(arguments)) })
  53. bot.on('messageDeleteBulk', function() { console.log('messageDeleteBulk', Array.from(arguments)) })
  54. bot.on('messageReactionAdd', function() { console.log('messageReactionAdd', Array.from(arguments)) })
  55. bot.on('messageReactionRemove', function() { console.log('messageReactionRemove', Array.from(arguments)) })
  56. bot.on('messageReactionRemoveAll', function() { console.log('messageReactionRemoveAll', Array.from(arguments)) })
  57. bot.on('messageUpdate', function() { console.log('messageUpdate', Array.from(arguments)) })
  58. bot.on('presenceUpdate', function() { console.log('presenceUpdate', Array.from(arguments)) })
  59. bot.on('rateLimit', function() { console.log('rateLimit', Array.from(arguments)) })
  60. bot.on('ready', function() { console.log('ready', Array.from(arguments)) })
  61. bot.on('reconnecting', function() { console.log('reconnecting', Array.from(arguments)) })
  62. bot.on('resume', function() { console.log('resume', Array.from(arguments)) })
  63. bot.on('roleCreate', function() { console.log('roleCreate', Array.from(arguments)) })
  64. bot.on('roleDelete', function() { console.log('roleDelete', Array.from(arguments)) })
  65. bot.on('roleUpdate', function() { console.log('roleUpdate', Array.from(arguments)) })
  66. bot.on('typingStart', function() { console.log('typingStart', Array.from(arguments)) })
  67. bot.on('typingStop', function() { console.log('typingStop', Array.from(arguments)) })
  68. bot.on('userNoteUpdate', function() { console.log('userNoteUpdate', Array.from(arguments)) })
  69. bot.on('userUpdate', function() { console.log('userUpdate', Array.from(arguments)) })
  70. bot.on('voiceStateUpdate', function() { console.log('voiceStateUpdate', Array.from(arguments)) })
  71. bot.on('warn', function() { console.log('warn', Array.from(arguments)) })
  72. */
  73. bot.login('NTA5NzMzOTczNjQ0Mjc5ODE4.DsSLOw.AeKUx4C-ceWxHYjf1tbephaRDxw')
  74. module.exports = bot