Reputation: 144
I want to role everyone in my server with a command I call p!roleall <role>
, but it's not ignoring bots and I need help. No errors were provided. Thanks.
@client.command()
async def roleall(ctx, role: discord.Role):
for i in ctx.guild.members:
if i == i.bot:
ctx.send('e')
try:
await i.add_roles(role)
except discord.errors.Forbidden:
await ctx.send(f'`i do not have permissions to role {i.name}`')
pass
Upvotes: 1
Views: 459
Reputation: 31
try putting an
else:
before the try.
Also, change ctx.send('e')
to await ctx.send('e')
Upvotes: 1
Reputation: 1893
There are a few issues with your code. Firstly, each ctx.send() requires an await. In regards to the i.bot, this returns a boolean, so no need to compare it.
The issue of it not ignoring bots stems from you not instructing the program to skip the rest of the code. A continue
statement will do that for you.
@client.command()
async def roleall(ctx, role: discord.Role):
for i in ctx.guild.members:
if i.bot:
await ctx.send('e')
continue
try:
await i.add_roles(role)
except discord.errors.Forbidden:
await ctx.send(f'`i do not have permissions to role {i.name}`')
pass
Upvotes: 4