Comments (8)
Correct me if I'm wrong (It's been a really long time since I last worked with plugAPI) but I think a way to implement this feature would be by first creating a getUserByName
function that returns an user object, then use that user's id in order to ban him.
https://github.com/plugCubed/plugAPI/wiki/%5Bactions%5D-getUsers
bot.getUserByName = function(name) {
return bot.getUsers().filter(user => user.username === name);
}
Then you can do (in your command handler or anywhere else):
bot.moderateBanUser(bot.getUserByName('WiBla').id);
You can check the wiki for more info on banning people with
reasons and to set the duration as well : https://github.com/plugCubed/plugAPI/wiki/%5Bactions%5D-moderateBanUser
Keep in mind that I haven't tested any of this code but I'm fairly confident it should work!
Hope this helps 😄
from plugapi.
Thank you so much for providing this. I tried it, and it doesn't work for me. I'm assuming where you have 'WiBla' below is where I would use my input variable?
bot.moderateBanUser(bot.getUserByName('WiBla').id);
from plugapi.
My pleasure!
Indeed, you need to substitute my username with the actual one you need, you should hopefully have this inside a variable as you said :)
Also, I've just looked at the command event after being told by @thedark1337 that plugAPI already provide you a user ID!
https://github.com/plugCubed/plugAPI/wiki/%5Bevents%5D-command
And indeed it does, so you should be able to do:
bot.on('command:ban', function(cmd) {
bot.moderateBanUser(cmd.mentions[0].id);
});
In this very crude example, I'm only getting the first mentioned user's id (mentions[0]
), but since it is an array, you can loop through all of its content!
Also, it goes without saying that this example does not check for user permission, both on the user that triggered the command but also for the bot itself. You should always do this and even more so with a moderation command.
With all of that, I hope you will be able to make the feature you wanted!
Please let us know how it went and if you ever need more help!
from plugapi.
Thanks so much again for helping me. I wish I was more knowledgeable about this stuff. I'm trying though! :) I'm afraid I'm confused again. Should I still use your code, plus this new snippet? Do I just use this new snippet? When I started doing this I kind of latched onto an older bot and did my own thing from there. Should all commands be done the way you have provided with bot.on('command:ban', function(cmd) {}, or is this not to actually run a command? Again sorry for the questions, i'm trying to become familiar with it all. I'd like to do a complete re-write but I am not sure I'm knowledgeable enough yet. Here is the current command that i'm playing with. I'm testing with bot.moderateAddDJ(); first before I move onto my ban commands.
case ".test":
if (bot.havePermission(data.from.id, roleHost)) {
let username = qualifier;
let usernameAdd = S(username).chompLeft('@').s;
bot.moderateAddDJ(bot.getUserByName(usernameAdd).id);
}
break;
from plugapi.
https://plugcubed.github.io/plugAPI/
Sorry its not very well documented, but, linked is the docs to the API
the way WiBla just showed is the official commands handler for plugAPI and 99% of the time it works, although i believe there's still a few bugs related to it.
That way would however require you needing to rewrite your bot so it uses the API's way of writing commands, or you can test out the get user by name way if you want to run your own command handler.
from plugapi.
Looks like I have a bot to re-write. :)
from plugapi.
Ok guys, I redid my commands using this new method and while it works for most everything, I'm having problems with waitlist bans/unbans and mute/unmute. Nothing happens. I'm hoping my code is just wrong, but shouldn't this work if I have the duration and reason assigned to the variables I'm using? I tried it without and it didn't work either.
.wlban @username
.wlunban @username
bot.on('command:wlban', function(data) {
if (bot.havePermission(data.from.id, roleManager)) {
bot.moderateWaitListBan(data.mentions[0].id, wlbanGenre, wlbanLong);
}
});
My wait list unban as well.
bot.on('command:wlunban', function(data) {
if (bot.havePermission(data.from.id, roleManager)) {
bot.moderateWaitListUnban(data.mentions[0].id);
}
});
from plugapi.
I figured it out. :) Thanks for all the help with this everyone.
from plugapi.
Related Issues (20)
- Errors in callback functions passed to playlist methods are mishandled HOT 2
- Should treat URLs as atoms when splitting long chat messages HOT 5
- Use ES6 Promise in place of callbacks HOT 5
- The advance event when last DJ finishes has djs.length == 2 HOT 2
- getPlaylists callback argument is not a RESTCallback HOT 6
- Chat events mentions are always [] HOT 3
- Duplicate advance event on skip (some times) HOT 2
- Playlist management functions some times silently fail HOT 5
- Cannot read property 'length' of undefined HOT 3
- Bot gets 403 error, restarts at random intervals HOT 7
- addToWaitList throws 403 error when target user has no playlists HOT 3
- Errors trying to perform npm install plugapi HOT 2
- Error after connection with account without playlist HOT 2
- Not sure if playlist functions are working properly
- Unsupported events
- User.language is null HOT 2
- Room Description HOT 8
- Have a bot.
- I'm using your api for a plug bot
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 plugapi.