Advertisement
3MoSteve

Private Text Channels

Jul 16th, 2020
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.30 KB | None | 0 0
  1.  
  2. //n3k4a is two xd
  3. const fs = require ('fs');
  4. const PChannels = require('./PChannels.json')
  5. function savePChannels () {
  6. fs.writeFileSync ('./PChannels.json', JSON.stringify (PChannels), (err) => {
  7. if (err) throw err;
  8. });
  9. };
  10. client.on ('message', Message => {
  11. if ((!Message.guild) || (Message.author.bot)) return null;
  12. if (Message.content.startsWith (prefix + 'myroom')) {
  13. var Category = Message.guild.channels.cache.find (Channel => (Channel.name.toLowerCase() == 'private channels') && (Channel.type == 'category'));
  14. if (!Category) return Message.channel.send('**Please create a category with name: `Private Channels`**');
  15. if ((PChannels[Message.author.id+Message.guild.id]) && (Message.guild.channels.cache.get (PChannels[Message.author.id+Message.guild.id].channel.id))) return Message.channel.send('**You have already created a channel.**');
  16. else {
  17. Message.guild.roles.create ({
  18. data: {
  19. name: `pr-${Message.author.username}`
  20. }
  21. }).then (async (Role) => {
  22. Message.guild.channels.create (`${Message.author.username}`, {
  23. type: 'text',
  24. parent: Category,
  25. reason: 'Private Channel By: '+Message.author.username,
  26. permissionOverwrites: [
  27. {
  28. id: Message.author.id,
  29. allow: ['MANAGE_CHANNELS', 'VIEW_CHANNEL', 'SEND_MESSAGES', 'SEND_TTS_MESSAGES', 'MANAGE_MESSAGES']
  30. },
  31. {
  32. id: Message.guild.id,
  33. deny: ['VIEW_CHANNEL']
  34. }
  35. ]
  36. }).then (async (Channel) => {
  37. Message.member.roles.add (Role);
  38. PChannels [Message.author.id+Message.guild.id] = {
  39. "channel": {
  40. "id": Channel.id
  41. },
  42. "Category": {
  43. "id": Category.id
  44. },
  45. "User": {
  46. "id": Message.author.id
  47. },
  48. "Role": {
  49. "id": Role.id
  50. }
  51. };
  52. savePChannels ();
  53. Message.reply ('**Successfully created your channel.**');
  54. });
  55. });
  56. }
  57. } else if (Message.content.startsWith (prefix + 'psettings')) {
  58. if (!PChannels[Message.author.id+Message.guild.id]) return Message.channel.send('**You have to setup your channel first.**');
  59. var Channel = Message.guild.channels.cache.get (PChannels[Message.author.id+Message.guild.id].channel.id);
  60. var args = Message.content.split (' ');
  61. if (!Channel) {
  62. delete PChannels[Message.author.id+Message.guild.id];
  63. savePChannels();
  64. Message.channel.send('**Your channel is deleted, please setup a new channel.**');
  65. } else {
  66. if (!args [1]) return Message.channel.send (`**Example: ${args [0]} \`add/remove/deleteChannel\`**`)
  67. if (!['add', 'remove', 'deletechannel'].includes (args [1].toLowerCase())) return Message.channel.send ('** :poop: كل**');
  68. if (args [1].toLowerCase () == "add") {
  69. var user = Message.mentions.members.first() || Message.guild.members.cache.get (args [2]);
  70. if (!user) return Message.channel.send('**I can\'t find this member.**');
  71. Channel.createOverwrite (user.id, {
  72. SEND_MESSAGES: true,
  73. READ_MESSAGE_HISTORY: true,
  74. VIEW_CHANNEL: true
  75. }, `Added to the channel by: ${Message.author.tag}`);
  76. Message.channel.send('**Successfully.**');
  77.  
  78. } else if (args[1].toLowerCase () == "remove") {
  79. var user = Message.mentions.members.first() || Message.guild.members.cache.get (args [2]);
  80. if (!user) return Message.channel.send('**I can\'t find this member.**');
  81. Channel.updateOverwrite (user.id, {
  82. VIEW_CHANNEL: false,
  83. READ_MESSAGE_HISTORY: false,
  84. SEND_MESSAGES: false
  85. }, `Removed from the channel by: ${Message.author.tag}`);
  86. Message.channel.send('**Successfully.**');
  87. } else if (args [1].toLowerCase () == "deletechannel") {
  88. Channel.delete ();
  89. var role = Message.guild.roles.cache.get (PChannels[Message.author.id+Message.guild.id].Role.id);
  90. if(role) role.delete();
  91. delete PChannels[Message.author.id+Message.guild.id];
  92. savePChannels();
  93. Message.channel.send('**Done**');
  94. }
  95. }
  96. }
  97. });
  98.  
  99. //By 3Mo_Steve ,_,
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement