question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`discord.Message.guild` is always `None`

See original GitHub issue

Summary

discord.Message.guild is always None everytime in on_message event

Reproduction Steps

  1. make simple on_message event
  2. try access any value inside message.guild like message.guild.id
  3. run and try say anything inside a guild
  4. errors
Ignoring exception in on_message
Traceback (most recent call last):
  File "C:\Users\moopi\AppData\Local\pypoetry\Cache\virtualenvs\botjam_mod-WKqEDRqB-py3.9\lib\site-packages\discord\client.py", line 375, in _run_event
    await coro(*args, **kwargs)
  File "F:\Desktop\botjam mod\src\automod.py", line 138, in on_message
    await self.profanity_checker(message)
  File "F:\Desktop\botjam mod\src\automod.py", line 90, in profanity_checker
    if db[str(message.guild.id)]["prevent_swearing"] == False:
AttributeError: 'NoneType' object has no attribute 'id'

Minimal Reproducible Code

import discord
from discord.ext import commands
class g(commands.Cog):
    def __init__(self,bot):
        self.bot = bot
    @commands.Cog.listener()
    async def on_message(self, message: discord.Message) -> None:
        message.guild.id

async def setup(bot: commands.Bot):
    await bot.add_cog(g())

Expected Results

discord.Message.guild.id isn’t None

Actual Results

discord.Message.guild.id is None

Intents

discord.Intents.all()

System Information

- Python v3.9.7-final
- discord.py v2.0.0-alpha
    - discord.py pkg_resources: v2.0.0a4154+g832d2c05
- aiohttp v3.8.1
- system info: Windows 10 10.0.19044

Checklist

  • I have searched the open issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have removed my token from display, if visible.

Additional Context

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
timelessnessescommented, Apr 25, 2022

i figured it out

0reactions
Rapptzcommented, Apr 22, 2022

all() should enable all intents right?

Yes.

If you want to further debug this issue turn on logging and print out what message.channel is.

Read more comments on GitHub >

github_iconTop Results From Across the Web

discord js message.guild is always null message.member
A message sent in private message to the both will not have a guild property, there is also the possibility of partials but...
Read more >
get_member returns none always #5867 - Rapptz/discord.py
A recent update to Discord seems to have caused get_member when using a guild to not return the member. There was a sudden...
Read more >
get_member always returns None (discord.py) : r/Discord_Bots
I'm trying to get my bot to 'fetch' member object from user id as an int. I have all Privileged Gateway Intents turned...
Read more >
API Reference - discord.py
The number of guilds to retrieve. If None , it retrieves every guild you have access to. Note, however, that this would make...
Read more >
Discord Developer Portal — Documentation — Guild
ALL_MESSAGES, 0, members will receive notifications for all messages by default ... NONE, 0, guild has not unlocked any Server Boost perks.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found