UNPKG

lutex-bits-transfer

Version:

A simple library for monitoring transfer messages in Discord, allowing users to wait for specific bot transfer confirmations.

48 lines (42 loc) 2.34 kB
/** * * @param {Client} client - The Discord client instance. * @param {TextChannel} channel - The channel to monitor for message updates. * @param {Object} options - Options for the transfer monitoring. * @param {string} options.botId - The bot's user ID responsible for the transfer. * @param {string} options.userId - The user ID of the recipient. * @param {number} options.amount - The amount expected to be transferred. * @param {number} [options.duration=60000] - Time in milliseconds to wait for the transfer. * @returns {Promise<boolean>} - Resolves to true if the transfer was successful, otherwise false. */ async function LutexBits(client, channel, { botId, userId, amount, duration = 60000 }) { const allowedBotIds = ['451379187031343104', '1276522930653630556']; if (!userId) throw new Error("Missing required parameter: userId"); if (amount === undefined) throw new Error("Missing required parameter: amount"); const user = await client.users.fetch(userId); return new Promise((resolve) => { const filter = (oldMessage, newMessage) => allowedBotIds.includes(newMessage.author.id) && ( newMessage.content.includes(`<:yes:1284538119420383282> **Transfer successful! You have transferred \`\`$${amount}\`\``) && newMessage.content.includes(`<@${userId}>`) && newMessage.content.includes("has been deducted** <:xpluna:1284524822306750544>") || newMessage.content.includes(`You have successfully transferred \`\`$${amount}\`\``) && newMessage.content.includes(`<@${userId}>`) || newMessage.content === `**> <:yea:1079670590807474216> Successfully transfered \`$${amount}\` bits to ${user.username}!**` ); const listener = (oldMessage, newMessage) => { if (filter(oldMessage, newMessage)) { resolve(true); client.off('messageUpdate', listener); } }; // إضافة listener للحدث messageUpdate client.on('messageUpdate', listener); setTimeout(() => { resolve(false); client.off('messageUpdate', listener); }, duration); }); } module.exports = LutexBits;