Comments (3)
Mentok di 17.
Sebenarnya bisa dikurangin lagi, tapi ngorbanin ini
if (!user) {
userId = args[0];
} else {
userId = user.id;
}
Nanti jadi gak bisa nge-timeout pake ID, bisanya pake mention. Gimana?
from wpu_bot.
Nanti jadi gak bisa nge-timeout pake ID, bisanya pake mention. Gimana?
Udah ada utility function buat dapetin user yang dimention.
Code nya bisa dilihat disini:
Lines 17 to 29 in 314e6ac
misal format command timeout begini ;timeout @manh21 28s
bisa dibuat begini
const timeCalc = {
s: (1),
m: (60),
h: (60 * 60),
d: (60 * 60 * 24)
};
const user = getUserFromMention(args[0]);
if(!user) return; // User tidak ditemukan
const timeType = args[1].slice(-1);
if(!['s', 'm', 'h', 'd'].includes(timeType)) return; // Check format waktu apakah sudah sesuai
const duration = parseInt(args[1].slice(0, -1)) || 0;
const durationMs = Math.floor(duration * (timeCalc[timeType] ?? 1) * 1000); // Convert duration to miliseconds
if(durationMs >= 2419200001 ) return; // check apakah durasi melebihi batas maksimum
Kalo mau dibuat multiple user bisa begini juga
format: ;timeout @manh21 @dhafitf 28s
const timeCalc = {
s: (1),
m: (60),
h: (60 * 60),
d: (60 * 60 * 24)
};
// Ambil user array
const userArr = [];
args.foreach((x, i) => {
if(!args[i+2]) return; // Check dua array ke depan apakah masih ada, last array adalah waktu jadi +2
const user = getUserFromMention(args[0]);
if(!user) return; // bukan user
userArr.push(user);
})
const timeType = args[-1].slice(-1);
if(!['s', 'm', 'h', 'd'].includes(timeType)) return; // Check format waktu apakah sudah sesuai
const duration = parseInt(args[-1].slice(0, -1)) || 0;
const durationMs = Math.floor(duration * (timeCalc[timeType] ?? 1) * 1000); // Convert duration to miliseconds
if(durationMs >= 2419200001 ) return; // check apakah durasi melebihi batas maksimum
from wpu_bot.
Lines 17 to 29 in 314e6ac
Sepertinya code diatas hanyalah untuk mendapatkan User. Sedangkan timeout ada di GuildMember. Jadi masih perlu penambahan lagi
let user = getUserFromMention(args[0], client);
if (!user) {
user = args[0];
}
let member;
try {
member = await msg.guild.members.fetch(user);
} catch (error) {
return msg.reply(":x: User not found");
}
Full code kira-kira bakalan kaya gini
const split = msg.content.split(/ +/);
const command = split[0].toLowerCase();
const args = split.slice(1);
if (command === `${process.env.PREFIX}timeout`) {
if (!checkRoles(msg)) return;
let user = getUserFromMention(args[0], client);
if (!user) {
user = args[0];
} // biar bisa pake id
let member;
try {
member = await msg.guild.members.fetch(user);
} catch (error) {
return msg.reply(":x: User not found");
} // untuk mendapatkan GuildMember
if (args.length < 2) {
return msg.reply("Please mention the user & set the time");
} // apabila author tidak mencantumkan user dan juga waktu
if (
member.roles.highest.position >= msg.guild.me.roles.highest.position &&
msg.member.roles.highest.position
) {
return msg.reply(
"You can't do this to user with the same or a higher role."
);
} // untuk mengecek posisi role
const timeCalc = {
s: 1,
m: 60,
h: 60 * 60,
d: 60 * 60 * 24,
};
const timeType = args[1].slice(-1);
if (!["s", "m", "h", "d"].includes(timeType)) return; // Check format waktu apakah sudah sesuai
const duration = parseInt(args[1].slice(0, -1)) || 0;
const durationMs = Math.floor(duration * (timeCalc[timeType] ?? 1) * 1000); // Convert duration to miliseconds
const reason = args.slice(2).join(" ");
const timeoutEmbed = new MessageEmbed()
.setColor("#992d22")
.setDescription(`<@${member.id}> has been timeout`);
member.timeout(durationMs, reason).catch(console.error());
if (durationMs > 2419200001) {
return msg.reply("Maximal timeout is 28d");
}
sendMsg(msg.channel, { embeds: [timeoutEmbed] });
}
from wpu_bot.
Related Issues (17)
- Ketidakjelasan prefix pada bot
- Error: point system when non user chat
- Use slash commands for future commad
- point system: add or decrease point for multiple user
- point system: modprofile doesn't cover user with Mod-Team and Bellshade-Team
- react emot HOT 2
- Translator HOT 1
- fitur game HOT 2
- update system point : add more point & add reason HOT 1
- Fix sticker auto triggered when mentioned HOT 1
- React Emote
- stiker batu HOT 4
- Add History log in Point system
- [Feature] Activity Starter HOT 1
- Error message ketika check permission HOT 2
- [Feature] Helper list command HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wpu_bot.