Hey everyone! I’m new to coding and I’m working on a Discord bot. I’m trying to make it so users can input between 2 and 10 teams for a check-in system. The bot works fine with 10 teams, but when fewer teams are entered, I get an error saying ‘NoneType’ object has no attribute ‘name’.
I think I know why it’s happening. When fewer than 10 teams are provided, some team variables end up as None and therefore lack a name attribute. However, I’m puzzled why the code still attempts to access the name attribute even when the condition should skip it.
Below is a simplified version of my code:
@bot.command()
async def set_teams(ctx, *teams):
team_names = []
for team in teams[:10]:
if team != 'None':
team_names.append(team.name)
await ctx.send(f'{len(team_names)} teams added: {team_names}')
I’ve experimented with adjusting the indentation and even using a pass statement, but the error persists. Can someone please help me understand what’s causing this issue? Thanks!