0

I'm trying to make a bot for my friend's server and he wants me to create an alarm system. I cannot get this member in an if statement to actually work

My code:

@commands.command(aliases=['an'])
async def attacknorth(self, ctx, member:discord.Member):
    guild = ctx.guild
    alarmRole = discord.utils.get(guild.roles, name="Alarm Owner")

    if member == alarmRole:
        await ctx.send("North kingdom has alarm role")
    else:
        await ctx.send("They dont have alarm role")
Lukas Thaler
  • 2,672
  • 5
  • 15
  • 31
Wep
  • 7
  • 1
  • 1
    I assume members _have_ roles, but you're checking if member is _equal_ to a role... – John Gordon Dec 15 '21 at 01:32
  • maybe first use `print()` to see what you have in variables. it is called `"print debuging"`. Maybe you compare wrong values. – furas Dec 15 '21 at 03:32
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Dec 21 '21 at 18:15

1 Answers1

0

As John Gordon had mentioned in the comments, you are checking if the member is equal to a role, rather than if the member has the role. You can use the discord.Member.roles attribute, which is a list, and check if the Alarm Owner role is in this list. Please view the revised code below.

@commands.command(aliases=['an'])
async def attacknorth(self, ctx, member:discord.Member):
    guild = ctx.guild
    alarmRole = discord.utils.get(guild.roles, name="Alarm Owner")

    if alarmRole in member.roles:
        await ctx.send("North kingdom has alarm role")
    else:
        await ctx.send("They don't have alarm role")

Command working as expected

Helpful Links:

Bagle
  • 2,326
  • 3
  • 12
  • 36
  • Thanks really appreciate it, worked wonders on me! – Wep Dec 16 '21 at 03:05
  • @Wep if this answer has helped you, do accept this as the answer to your question by pressing the tick button beneath this answer's upvote and downvote – Bagle Dec 19 '21 at 02:09