Advertisement
Sochum123

Untitled

Jun 17th, 2022 (edited)
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.87 KB | None | 0 0
  1. const { Client, Collection, Intents } = require("discord.js");
  2. const fs = require("fs");
  3. const Discord = require('discord.js')
  4. const client = new Client({
  5. intents: [
  6. Intents.FLAGS.GUILDS,
  7. Intents.FLAGS.GUILD_EMOJIS_AND_STICKERS,
  8. Intents.FLAGS.GUILD_INTEGRATIONS,
  9. Intents.FLAGS.GUILD_MESSAGES,
  10. Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
  11. ],
  12. });
  13. // run a command to see
  14. // removed some intents since they were useless and it was crashing the bot even though i enabled them in discord developers
  15. let discord = require("discord.js");
  16. let path = require("path");
  17. let mongoose = require("mongoose");
  18. let commands = new Collection();
  19. let slashcommands = new Collection();
  20. const { Database } = require("quickmongo");
  21. const dbquick = new Database("mongodb+srv://#@cluster0.#.mongodb.#/Data?#=#&w=majority");
  22. let timeouts = dbquick;
  23. let ms = require("ms");
  24. let config = {
  25. prefix: ["<@933927497697984573>", "<@!933927497697984573>"],
  26. };
  27. let schema = mongoose.model(
  28. `economy`,
  29. new mongoose.Schema({
  30. User: String,
  31. Bobux: Number,
  32. Bix: Number,
  33. CreatedAt: Number,
  34. TotalEarned: Number,
  35. TotalSpent: Number,
  36. BasicBoxes: Number,
  37. HighTierBoxes: Number,
  38. GodBoxes: Number,
  39. VoteBoxes: Number,
  40. })
  41. );
  42.  
  43. const prefixschema = require("./commands/prefixes");
  44. let prefix = async function (message) {
  45. let custom;
  46.  
  47. if (!message.guild) {
  48. return (custom = "<@!933927497697984573>");
  49. }
  50. const data = await prefixschema
  51. .findOne({ GuildId: message.guild.id })
  52. .catch((err) => console.log(err));
  53.  
  54. if (data) {
  55. custom = data.Prefix;
  56. } else {
  57. custom = "<@!933927497697984573>";
  58. }
  59. return custom;
  60. };
  61.  
  62. const economy = {
  63. async getUsers() {
  64. let thing = await schema.find()
  65. return thing
  66. },
  67. async getBal(User) {
  68. return await schema
  69. .findOne({
  70. User,
  71. })
  72. .then((d) => (d ? d.Bobux : 0));
  73. },
  74. async getBix(User) {
  75. return await schema
  76. .findOne({
  77. User,
  78. })
  79. .then((d) => (d ? d.Bix : 0));
  80. },
  81.  
  82. async addBal(User, Bobux) {
  83. return await schema.findOne({ User }, async (err, data) => {
  84. if (err) throw err;
  85. if (data) {
  86. data.Bobux += Number(Bobux);
  87. } else {
  88. data = new schema({ User, Bobux });
  89. }
  90. data.save();
  91. });
  92. },
  93. async AddBix(User, Bix) {
  94. return await schema.findOne({ User }, async (err, data) => {
  95. if (err) throw err;
  96. if (data) {
  97. data.Bix += Number(Bix);
  98. } else {
  99. data = new schema({ User, Bix });
  100. }
  101. data.save();
  102. });
  103. },
  104.  
  105. async subBal(User, Bobux) {
  106. return await schema.findOne({ User }, async (err, data) => {
  107. if (err) throw err;
  108. if (data) {
  109. data.Bobux -= Number(Bobux);
  110. } else {
  111. data = new schema({ User, Bobux });
  112. }
  113. data.save();
  114. });
  115. },
  116. async killUser(User) {
  117. return await schema.findOne({ User }, async (err, data) => {
  118. let amount = 0
  119. if (err) throw err;
  120. if (data) {
  121. var randombal = Math.floor(Math.random() * 19) + 1;
  122. var num = 1-(randombal / 100)
  123. var amountlost = (randombal / 100)
  124. var amountlost2 = amountlost * (data.Bobux).toFixed(0)
  125.  
  126. var newbal = (data.Bobux) * num
  127. data.Bobux = newbal.toFixed(0)
  128. amount = amountlost2
  129. } else {
  130. data = new schema({ User, Bobux });
  131. }
  132. data.save();
  133. return amount
  134. });
  135. },
  136.  
  137. };
  138. function commandHandler(epath) {
  139. fs.readdirSync(path.normalize(epath)).map((f) => {
  140. const File = require(path.join(__dirname, `.`, epath, f));
  141. commands.set(File.name, File);
  142. });
  143. }
  144. function slashcommandHandler(slashpath) {
  145. fs.readdirSync(path.normalize(slashpath)).map((f) => {
  146. const File = require(path.join(__dirname, `.`, slashpath, f));
  147. slashcommands.set(File.data.name, File);
  148. });
  149. }
  150. function getCommand(cmd) {
  151. return commands.has(cmd) ? commands.get(cmd) : false;
  152. }
  153. commandHandler("./commands");
  154. slashcommandHandler("./slashcommands");
  155.  
  156.  
  157.  
  158. client.on("ready", async () => {
  159. console.log("bot on");
  160. client.user.setActivity(`$help || $donatehelp `);
  161. await mongoose.connect(
  162. `mongodb+srv://##&w=majority
  163. `,
  164. {
  165. useNewUrlParser: true,
  166. useUnifiedTopology: true,
  167. }
  168. );
  169. });
  170. client.on("guildMemberAdd", async (member) => {
  171. if (Date.now() - member.user.createdAt < 600 * 60 * 60 * 24 * 10) {
  172. if (member.guild.id !== "803403643868414024") {
  173. return;
  174. }
  175. let role = member.guild.roles.cache.get("896438105379328011");
  176.  
  177. await member.roles.add(role).then(console.log(`Done`));
  178. client.channels.cache
  179. .get("896564381205270559")
  180. .send(
  181. `New sus member maybe! Be alert. Sus User id: ${member.id}, tag: ${member.user.tag}. He has been muted for now. `
  182. );
  183. } else {
  184. return;
  185. }
  186. });
  187.  
  188. client.on("messageCreate", async (message) => {
  189. if(message.author.bot) {
  190. return
  191. }
  192. if(message.author.id == '622442733294059526' || message.author.id === '482345661736681472' || message.author.id == '649755456927170601' || message.author.id == '758887378520768544' || message.author.id == '836361597701193748' ) {
  193.  
  194. const p = await prefix(message);
  195. if (
  196. message.author.bot ||
  197. !message.guild ||
  198. !message.content.toLocaleLowerCase().startsWith(p)
  199. )
  200. return;
  201. const args = message.content.slice(p.length).trim().split(" ");
  202. const cmd = args.shift().toLocaleLowerCase();
  203. message.guild.commands.fetch()
  204. .catch({
  205. //noperms
  206. })
  207. const command =
  208. getCommand(cmd) ||
  209. commands.find((a) => a.aliases && a.aliases.includes(cmd));
  210. if (!command) return;
  211. if (command.timeout) {
  212. if (timeouts.has(`${command.name}${message.author.id}`)) {
  213. let embed = new Discord.MessageEmbed().setDescription(
  214. `You can't use this commmand for another ${ms(
  215. timeouts.get(`${command.name}${message.author.id}`) - Date.now(),
  216. { long: true }
  217. )}`
  218. );
  219. message.channel.send({ embeds: [embed] });
  220. return;
  221. }
  222. command.run(client, message, args).catch(console.error);
  223. timeouts.push(
  224. `${command.name}${message.author.id}`,
  225. Date.now() + command.timeout
  226. );
  227. setTimeout(() => {
  228. timeouts.delete(`${command.name}${message.author.id}`);
  229. }, command.timeout);
  230. } else return command.run(client, message, args).catch(console.error);
  231.  
  232. } else {
  233. return message.reply(`You do not have permission to use this bot`);
  234. }
  235. });
  236. client.on("guildMemberUpdate", function (oldMember, newMember) {
  237. const wc = new Discord.WebhookClient(
  238. "#', '#-#-bWkb_9"
  239. );
  240. if (oldMember.roles.cache.size !== newMember.roles.cache.size) {
  241. //donator role
  242. if (
  243. !oldMember.roles.cache.has("851156630748921927") &&
  244. newMember.roles.cache.has("851156630748921927")
  245. ) {
  246. client.channels.cache
  247. .get("863119973384061008")
  248. .send(`<@${newMember.id}> has just donated!`);
  249. }
  250.  
  251. if (
  252. oldMember.roles.cache.has("851156630748921927") &&
  253. !newMember.roles.cache.has("851156630748921927")
  254. ) {
  255. client.channels.cache
  256. .get("863119973384061008")
  257. .send(
  258. `<@${newMember.id}> has just cancelled their subscription (test)!`
  259. );
  260. }
  261. }
  262. });
  263.  
  264. client.on("guildCreate", async (guild, message) => {
  265. const Embed = new Discord.MessageEmbed()
  266. .setTitle("Boblox Help!")
  267.  
  268. .addFields(
  269. { name: "💰 How to earn Bobux", value: "`$earnhelp`" },
  270. {
  271. name: "💸How to create and earn bobux off a game",
  272. value: "`$gamehelp`",
  273. },
  274. {
  275. name: "💹 Complete Guide on how to use boblox and become the richest",
  276. value: "`$guide`",
  277. },
  278. {
  279. name: "🧧 Donate to support us and recieve many Benefits",
  280. value: "`$donatehelp`",
  281. },
  282. {
  283. name: "💹 How to trade in the Boblox Stonk Market",
  284. value: "`$stonkhelp`",
  285. },
  286. { name: "💱 View all the leaderboards", value: "`$lbhelp`" },
  287. {
  288. name:
  289. "🏛 Join or Create A Group And Become The Biggest Group With Your Fellow Members ",
  290. value: "`$grouphelp`",
  291. }
  292. );
  293.  
  294. const owner = await guild.members.fetch(guild.ownerId);
  295. owner
  296. .send("Support/community server: https://discord.gg/BcNx4SUq54")
  297. .catch(async (err) => {
  298. console.log(err);
  299. });
  300.  
  301. owner.send(Embed).catch(async (err) => {
  302. console.log(err);
  303. });
  304.  
  305. owner
  306. .send(
  307. "Voting for boblox will give you a huge headstart on the bot \n https://top.gg/bot/809483262710775817/vote"
  308. )
  309. .catch(async (err) => {
  310. console.log(err);
  311. });
  312. });
  313.  
  314. client.on("interactionCreate", async (interaction) => {
  315. if (!interaction.isCommand()) return;
  316. if(interaction.user.id == '622442733294059526' || interaction.user.id === '482345661736681472' || interaction.user.id == '649755456927170601' || interaction.user.id == '758887378520768544' || interaction.user.id == '836361597701193748') {
  317.  
  318.  
  319.  
  320. const command = slashcommands.get(interaction.commandName);
  321. if (!command) console.log(slashcommands);
  322. if (command.timeout) {
  323. if (timeouts.has(`${command.name}${interaction.user.id}`)) {
  324. let embed = new Discord.MessageEmbed().setDescription(
  325. `You can't use this commmand for another ${ms(
  326. timeouts.get(`${command.name}${interaction.user.id}`) - Date.now(),
  327. { long: true }
  328. )}`
  329. );
  330. await interaction.reply({ embeds: [embed] });
  331. return;
  332. }
  333. }
  334. try {
  335. await command.execute(interaction, interaction.client);
  336. timeouts.push(
  337. `${command.name}${interaction.user.id}`,
  338. Date.now() + command.timeout
  339. );
  340. }
  341.  
  342. catch (error) {
  343. console.log(`${error}`);
  344. await interaction.reply({
  345. content: "There was an error executing this command.",
  346. ephemeral: true,
  347. });
  348. }
  349. } else {
  350. await interaction.reply({ content: 'You do not have permission to use this bot', ephemeral: true });
  351.  
  352. }
  353. });
  354.  
  355.  
  356. client.login('###')
  357.  
  358.  
  359.  
  360. module.exports = { economy }
  361.  
  362.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement