Check user for a role - discord

I am trying to check if a user has a specific role, and if they have that role they can use the command but no matter if I have the role I get the else triggered.
Code
#bot.slash_command(name="test", description = "testing cmd")
async def test(ctx, member: discord.Member):
role = "1023451893575450665"
if get(member.roles, id=role):
await ctx.send("your application has been accepted")
else:
await ctx.send("your application has been denied")

If you know the role id, use the Member.get_role method. The role id should be left as an integer, not a string.
if member.get_role(role):
await ctx.send("your application has been accepted")
If you know the role name, you need to check through the member.roles property which is a list of Roles
if len(member_role for member_role in member.roles if member_role.name == role]):
await ctx.send("your application has been accepted")

Related

A specific role only reaction

I'm trying to get it so a specific role can react to the message to be able to ban the user, I have made the ability to be able to react to the message, and the author of the command can ban the user, but I want to make it so another role can do it as well
Here is what I have currently
def check(rctn, user):
return user.id == ctx.author.id and str(rctn) == '<:tick:837398197931868190>'
reaction, user = await bot.wait_for('reaction_add', check=check)
You can use #commands.has_permissions
For example you could make it:
#bot.command()
#commands.has_permissions(ban_members=True)
# rest of your code
This way only roles with the permissions to ban_members can use the command

how i get an user status and i give him a specific role, i tried but it doesn't work

async def on_message(message):
if message.content.startswith("-test"):
await message.channel.send("Checking for the Status :pencil:..")
time.sleep(1)
async def on_member_update(before, after):
if str("discord.gg / discord") in member.activities[0].name():
print("Correct Status giving role to User")
guild = client.get_guild(8516587165187561)
role = discord.utils.get(guild.roles, id=9157981598717517571)
await message.channel.send("roled")
i try to get an user status and if he have that status specified he get the role, i don't know why it doesn't work, i use discord.py
There's no need to put on_member_update in the code. It wouldn't work anyway even if you do due to the fact it's an event function, not something you can call on.
async def on_message(message):
if message.content.startswith("-test"):
await message.channel.send("Checking for the Status :pencil:..")
time.sleep(1)
if str("discord.gg / discord") in message.author.activities[0].name():
print("Correct Status giving role to User")
guild = client.get_guild(8516587165187561)
role = discord.utils.get(guild.roles, id=9157981598717517571)
await message.author.add_roles(role)
await message.channel.send("roled")
I've also added the await message.author.add_roles(role) part because there wasn't any command that assign roles in your original code.

How do you assign any role to a user in discord.js?

I don't want a command that whenever you do -role, it already has only one in place to give to a user. I would like one that whatever you put a role as the second argument, it gives that user that role (unless of course that role doesn't exist). So if you do -role #user Blue, it gives them the 'Blue' role, if you do -role #user Red, it gives them the 'Red' role.
I guess best similarity to this would be the Dyno bot, whatever role you put as the second argument, it gives that role to the user.
Try the following:
I suppose you use the command handler from the discordjs guide, so the args array is the array of words (arguments) after the command itself.
//search the role based on the name that the user provided:
let role = message.guild.roles.cache.find(role => role.name === args[1]);
//if the role doesn't exist, create it
if (!role) {
role = await message.guild.roles.create({ data: { name: args[1] } });
}
//get the mentioned user
const member = message.mentions.members.first();
//add the role to the user
member.roles.add(role);

How can I allow people to only kick members lower than their role with discord.py?

I'm trying to make a kick command using Python and the discord.py library, though I cannot figure out how to allow people to only be able to kick members lower than their role, so Moderators wouldn't be able to kick Admins.
enter image description here
You can compare the Member object with a function called top_role
An example code would be:
#client.command()
#commands.has_permissions(kick_members=True)
async def kick(ctx, member: discord.Member, *, reason=None):
if member.top_role >= ctx.author.top_role: # Check if the role is below the authors role
await ctx.send("You can only kick users with a lower role!")
return
else:
await member.kick(reason=reason)
await ctx.send(f"{member.id} got kicked with the reason: {reason}.")
Add all the moderators to a list and regular users to another list.
Like this;
string[] moderator = all moderators.
string[] regularUsers = all regular users.

How can I give member a role with role id?

role = client.get_role("697037307060027482")
await message.author.add_roles(role)
I Tried this, but Error occurs.
How can I give a role vith role id?
You can get guild and get role. Example:
#client.command()
async def addrole(ctx):
role = client.get_guild(your_guild_id).get_role(your_role_id)
await ctx.author.add_roles(role)

Resources