I'm very confused at how this error is occurring, it is only occurring when I use the kick/ban command in my bot and no other commands, I looked in the on_message function and it doesn't cause an error when I message anything else except from the kick/ban command and I'm not sure why. I am passing in guild correctly and there is an id attribute because the code is still working but it comes up with this anyway.
Here's the error:
Ignoring exception in on_message
Traceback (most recent call last):
File ".local/lib/python3.7/site-packages/discord/client.py", line 333, in _run_event
await coro(*args, **kwargs)
File "file path", line 1937, in on_message
await open_automod(guild)
File "file path", line 1920, in open_automod
if str(guild.id) in data:
AttributeError: 'NoneType' object has no attribute 'id'
Here's an example of a bot command that causes this error:
@bot.command(name='testlog')
@commands.has_permissions(kick_members=True)
async def kick (ctx, member:discord.Member, *reason):
moderator = ctx.message.author.id
server = ctx.guild.id
if member == None or member == moderator:
await ctx.channel.send("You cannot kick yourself")
return
if reason == None:
reason = "no reason stated"
reason = " ".join(reason)
message = f"You have been banned from {ctx.guild.name}. Reason: {reason}"
await member.send(message)
await ctx.channel.send(f"{member} has been kicked. Reason: {reason}")
await send_log('test', moderator, member.id, reason, server)
Here's the open_automod function:
async def open_automod(guild):
data = await get_automod_data()
if str(guild.id) in data:
return False
else:
data[str(guild.id)] = {}
data[str(guild.id)]["automodenabled"] = f'off'
data[str(guild.id)]["automodlogging"] = f'false'
data[str(guild.id)]["automodchannel"] = 0
with open("automoderator.json","w") as f:
json.dump(data,f)
return True
Here's the section of the code that is passing in 'guild':
@bot.event
async def on_message(message):
guild = message.guild
await open_automod(guild)
What I don't get is why this error only shows up on the message where im using kicks or bans or in the above case a test kick. Could anyone explain why i'm getting this error and why it only happens on this message? An example of the message would be 'h/testlog @user reason'
guildwill beNone- Łukasz Kwieciński