I am currently working on a small discord bot using the newest versions of pylint, python3.92, and discord.py.
While using discord intents I encountered a pylint error that has me stumped.
This is a more general question as whatever I am doing is still working and doing what I intend it to do in my actual project.
However this error I can't seem to work around or get rid off is seriously bothering me as I used discord.py intents as per the documentation as far as I know.
This snippet is from a test bot to showcase the specific errors.
import discord
from discord.ext import commands
intents = discord.Intents.default()
intents.members = True
intents.presences = True
bot = commands.Bot(command_prefix='.', intents=intents)
@bot.command()
async def ping(ctx):
ctx.send("pong")
bot.run('TOKEN')
Now pylint is showing me two errors in this code, both considering the intent attribute assignment.
From the docs:
import discord
intents = discord.Intents.default()
intents.typing = False
intents.presences = False
# Somewhere else:
# client = discord.Client(intents=intents)
# or
# from discord.ext import commands
# bot = commands.Bot(command_prefix='!', intents=intents)
One possibility I found is the following workaround:
intents = discord.Intents(members=True, presences=True)
However as I am planning to use different functions in one bot and don't want to have to add all intents I need manually I plan sticking to discord.Intents.default()
if possible.
These errors do not hinder the functionality or cause any other errors as far as I can tell. The error is the same with different types of intents, not just with privileged intents. My questions would be:
Unfortunately my knowledge of the language, discord.py and pylint is not advanced enough to change things around and get rid of the error in a proper way.
Thanks in advance!
In theory, the wrong code would look like this (source):
class Foo:
__slots__ = ('bar',)
def __init__(self, bar, baz):
self.bar = bar
self.baz = baz # [assigning-non-slot]
self.setup()
def setup(self):
pass
And the correct code like this:
class Foo:
__slots__ = ('bar', 'baz')
def __init__(self, bar, baz):
self.bar = bar
self.baz = baz
self.setup()
def setup(self):
pass
Now, if the code in this current form works for you, and especially if this is the official and easier way of using your dependencies... then it's a false positive from pylint and you can disable the message with # pylint: disable=assigning-non-slot
or even for the whole project with the pylintrc