I'm fairly new to scripting in Python, but I used stack overflow to create a command for a Discord bot that should kick all members with a given role. This is the code I currently have:
import discord
from discord.ext import commands
from discord.ext.commands import has_permissions
bot = commands.Bot(command_prefix = ".")
@bot.command()
#async def hello(ctx):
# await ctx.reply('Hello!')
@has_permissions(administrator=True)
async def kickMembers(ctx, role: discord.Role, reason: str=None):
await ctx.reply('Kicking members')
for member in ctx.guild.members:
await ctx.reply(f'Looping through member {member}')
if role in member.roles: # does member have the specified role?
await ctx.reply('Found a member, kicking!')
await ctx.guild.kick(member,reason=reason)
Now, the issue is that it begins to loop through, but completely freezes after sending the message 'Looping through member {member}'. It sends a message saying that it is looping through itself (the bot), but then freezes and does't loop through anyone else.
If anyone has any help that is much appreciated, thanks!