Roles in Bot
Closed this issue · 15 comments
Maybe you know how to do auto-assignment depending on the player's statistics? For example, the player wrote! Statg stats squad-fpp received cd 2.15 and automatically assigned a role in the KD 2+
The statg-bot uses discord.io internally. So if you would like to add a feature like adding roles to a user, I suggest that you look at the official discord.io docs which can be found here. Specifically the client.addToRole( {opts} [, callback] )
(link) should be able to do the thing you are asking for.
Although I have not tested this, your solution should look somewhat like the following:
// ... inside stats-cmd-handler.js starting at around line 104
if (avgStats.kills > 2) {
bot.addToRole({
userID: cmd.discordUser.id,
roleID: yourRoleID,
});
}
// ...
I don't really know how to get the role ID unfortunately, but you might be able to find that out by yourself ;)
Thank you, if you can, I will post here :)
I found the role number, but still it does not work out :(
https://discordhelp.net/role-id
Thanks for the link + I actually got assigning roles with the bot working. Here's what I did:
- Get the role id of the role you want to assign as described on the website you linked. The id will look something like
<@&42013374269>
. The bot will only need the42013374269
part. - Make sure your bot has the permission to assign roles. I did this by creating a seperate role for my bot and checking the
Manage Roles
box inside the role settings. Double check the permissions of your bot role. The order of your roles does matter as described in the Discord docs. - Add the following function call to
stats-cmd-handler.js
:
bot.addToRole({
serverID: cmd.discordUser.channelId,
userID: cmd.discordUser.id,
roleID: '42013374269', // change this role id to your role id
});
NOTE: I was missing the serverID
in my previous comment.
- Start the bot and type
!statg stats
in a public channel of your server. This did not seem to work with private text channels. - Enjoy your new role :)
Of course you can add if
s / else
s and removeFromRole()
calls to tailor the role assignments to your liking.
Did as you wrote, does not work in any way :(
Hm, hard to tell what's wrong. Please check the permissions of the role of your bot again. Discord's permission system is confusing as hell and the order of the roles does actually matter.
For example, the following works:
While this does not:
As described earlier, the "Manage Roles" permission has to be enabled for the role of your bot too:
If your permissions look good, you could replace
bot.addToRole({
serverID: cmd.discordUser.channelId,
userID: cmd.discordUser.id,
roleID: '42013374269', // change this role id to your role id
});
with
bot.addToRole({
serverID: cmd.discordUser.channelId,
userID: cmd.discordUser.id,
roleID: '42013374269', // change this role id to your role id
}, (error) => {
this.logger.debug(error);
});
and look at the console output or the combined.log
inside the logs
folder for any errors which might happen when trying to assign roles.
Looks like you are just starting out coding. Keep in mind that one of the hardest parts about programming is staying motivated and keep trying. Eventually it will work, you just need the diligence to get to the end ;) So good luck and have fun
ohhhh.....
undefined {
"name": "ResponseError",
"statusCode": 404,
"statusMessage": "NOT FOUND",
"response": {
"code": 10004,
"message": "Unknown Guild"
}
}
I correctly specify the ID of the role
Two days already nothing happens ((
Had the same error when typing !statg stats
to a private text channel where only me and the bot had permissions to do anything (for testing the bot). It worked in the default general
text channel though, so try typing there (or a similar text channel).
More info about discord guilds here
The channel is not private, everywhere I tried .. (((
the string is not correct:
serverID: cmd.discordUser.channelId,
You need to specify the ID Server from the discord
earned :) Thanks !!!!!!
So you found the problem and got it working?
Yes it works. The problem was in serverID: cmd.discordUser.channelId
I specified my server ID
Nice, glad to hear :)