Merge pull request #40 from Gnome-py/required-intents
Remove intents.default and make intents a required parameter
This commit is contained in:
commit
b28893aa36
@ -142,7 +142,6 @@ class Client:
|
||||
intents: :class:`Intents`
|
||||
The intents that you want to enable for the session. This is a way of
|
||||
disabling and enabling certain gateway events from triggering and being sent.
|
||||
If not given, defaults to a regularly constructed :class:`Intents` class.
|
||||
|
||||
.. versionadded:: 1.5
|
||||
member_cache_flags: :class:`MemberCacheFlags`
|
||||
@ -203,9 +202,12 @@ class Client:
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
intents: Intents,
|
||||
loop: Optional[asyncio.AbstractEventLoop] = None,
|
||||
**options: Any,
|
||||
):
|
||||
options["intents"] = intents
|
||||
|
||||
# self.ws is set in the connect method
|
||||
self.ws: DiscordWebSocket = None # type: ignore
|
||||
self.loop: asyncio.AbstractEventLoop = asyncio.get_event_loop() if loop is None else loop
|
||||
|
@ -120,8 +120,8 @@ class _DefaultRepr:
|
||||
_default = _DefaultRepr()
|
||||
|
||||
class BotBase(GroupMixin):
|
||||
def __init__(self, command_prefix, help_command=_default, description=None, **options):
|
||||
super().__init__(**options)
|
||||
def __init__(self, command_prefix, help_command=_default, description=None, *, intents: discord.Intents, **options):
|
||||
super().__init__(**options, intents=intents)
|
||||
self.command_prefix = command_prefix
|
||||
self.extra_events: Dict[str, List[CoroFunc]] = {}
|
||||
self.__cogs: Dict[str, Cog] = {}
|
||||
|
@ -480,16 +480,6 @@ class Intents(BaseFlags):
|
||||
self.value = self.DEFAULT_VALUE
|
||||
return self
|
||||
|
||||
@classmethod
|
||||
def default(cls: Type[Intents]) -> Intents:
|
||||
"""A factory method that creates a :class:`Intents` with everything enabled
|
||||
except :attr:`presences` and :attr:`members`.
|
||||
"""
|
||||
self = cls.all()
|
||||
self.presences = False
|
||||
self.members = False
|
||||
return self
|
||||
|
||||
@flag_value
|
||||
def guilds(self):
|
||||
""":class:`bool`: Whether guild related events are enabled.
|
||||
|
@ -152,6 +152,7 @@ class ConnectionState:
|
||||
handlers: Dict[str, Callable],
|
||||
hooks: Dict[str, Callable],
|
||||
http: HTTPClient,
|
||||
intents: Intents,
|
||||
loop: asyncio.AbstractEventLoop,
|
||||
**options: Any,
|
||||
) -> None:
|
||||
@ -194,12 +195,8 @@ class ConnectionState:
|
||||
else:
|
||||
status = str(status)
|
||||
|
||||
intents = options.get('intents', None)
|
||||
if intents is not None:
|
||||
if not isinstance(intents, Intents):
|
||||
raise TypeError(f'intents parameter must be Intent not {type(intents)!r}')
|
||||
else:
|
||||
intents = Intents.default()
|
||||
if not isinstance(intents, Intents):
|
||||
raise TypeError(f'intents parameter must be Intent not {type(intents)!r}')
|
||||
|
||||
if not intents.guilds:
|
||||
_log.warning('Guilds intent seems to be disabled. This may cause state related issues.')
|
||||
|
@ -26,5 +26,5 @@ class MyClient(discord.Client):
|
||||
async def before_my_task(self):
|
||||
await self.wait_until_ready() # wait until the bot logs in
|
||||
|
||||
client = MyClient()
|
||||
client = MyClient(intents=discord.Intents(guilds=True))
|
||||
client.run('token')
|
||||
|
@ -22,5 +22,5 @@ class MyClient(discord.Client):
|
||||
await asyncio.sleep(60) # task runs every 60 seconds
|
||||
|
||||
|
||||
client = MyClient()
|
||||
client = MyClient(intents=discord.Intents(guilds=True))
|
||||
client.run('token')
|
||||
|
@ -9,10 +9,8 @@ module.
|
||||
|
||||
There are a number of utility commands being showcased here.'''
|
||||
|
||||
intents = discord.Intents.default()
|
||||
intents.members = True
|
||||
|
||||
bot = commands.Bot(command_prefix='?', description=description, intents=intents)
|
||||
intents = discord.Intents(guilds=True, messages=True, members=True)
|
||||
bot = commands.Bot(command_prefix='t-', description=description, intents=intents)
|
||||
|
||||
@bot.event
|
||||
async def on_ready():
|
||||
|
@ -123,8 +123,11 @@ class Music(commands.Cog):
|
||||
elif ctx.voice_client.is_playing():
|
||||
ctx.voice_client.stop()
|
||||
|
||||
bot = commands.Bot(command_prefix=commands.when_mentioned_or("!"),
|
||||
description='Relatively simple music bot example')
|
||||
bot = commands.Bot(
|
||||
command_prefix=commands.when_mentioned_or("!"),
|
||||
description='Relatively simple music bot example',
|
||||
intents=discord.Intents(guilds=True, guild_messages=True, voice_states=True)
|
||||
)
|
||||
|
||||
@bot.event
|
||||
async def on_ready():
|
||||
|
@ -5,9 +5,8 @@ import typing
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
|
||||
intents = discord.Intents.default()
|
||||
intents.members = True
|
||||
|
||||
intents = discord.Intents(guilds=True, messages=True, members=True)
|
||||
bot = commands.Bot('!', intents=intents)
|
||||
|
||||
|
||||
|
@ -29,7 +29,7 @@ class MyBot(commands.Bot):
|
||||
return await super().get_context(message, cls=cls)
|
||||
|
||||
|
||||
bot = MyBot(command_prefix='!')
|
||||
bot = MyBot(command_prefix='!', intents=discord.Intents(guilds=True, messages=True))
|
||||
|
||||
@bot.command()
|
||||
async def guess(ctx, number: int):
|
||||
|
@ -17,5 +17,5 @@ class MyClient(discord.Client):
|
||||
msg = f'{message.author} has deleted the message: {message.content}'
|
||||
await message.channel.send(msg)
|
||||
|
||||
client = MyClient()
|
||||
client = MyClient(intents=discord.Intents(guilds=True, messages=True))
|
||||
client.run('token')
|
||||
|
@ -16,5 +16,5 @@ class MyClient(discord.Client):
|
||||
msg = f'**{before.author}** edited their message:\n{before.content} -> {after.content}'
|
||||
await before.channel.send(msg)
|
||||
|
||||
client = MyClient()
|
||||
client = MyClient(intents=discord.Intents(guilds=True, messages=True))
|
||||
client.run('token')
|
||||
|
@ -30,5 +30,5 @@ class MyClient(discord.Client):
|
||||
else:
|
||||
await message.channel.send(f'Oops. It is actually {answer}.')
|
||||
|
||||
client = MyClient()
|
||||
client = MyClient(intents=discord.Intents(guilds=True, messages=True))
|
||||
client.run('token')
|
||||
|
@ -14,8 +14,5 @@ class MyClient(discord.Client):
|
||||
await guild.system_channel.send(to_send)
|
||||
|
||||
|
||||
intents = discord.Intents.default()
|
||||
intents.members = True
|
||||
|
||||
client = MyClient(intents=intents)
|
||||
client = MyClient(intents=discord.Intents(guilds=True, members=True))
|
||||
client.run('token')
|
||||
|
@ -78,8 +78,6 @@ class MyClient(discord.Client):
|
||||
# If we want to do something in case of errors we'd do it here.
|
||||
pass
|
||||
|
||||
intents = discord.Intents.default()
|
||||
intents.members = True
|
||||
|
||||
intents = discord.Intents(guilds=True, members=True, guild_reactions=True)
|
||||
client = MyClient(intents=intents)
|
||||
client.run('token')
|
||||
|
@ -13,5 +13,5 @@ class MyClient(discord.Client):
|
||||
if message.content.startswith('!hello'):
|
||||
await message.reply('Hello!', mention_author=True)
|
||||
|
||||
client = MyClient()
|
||||
client = MyClient(intents=discord.Intents(guilds=True, messages=True))
|
||||
client.run('token')
|
||||
|
@ -3,7 +3,11 @@ import typing
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
|
||||
bot = commands.Bot(command_prefix=commands.when_mentioned, description="Nothing to see here!")
|
||||
bot = commands.Bot(
|
||||
command_prefix=commands.when_mentioned,
|
||||
description="Nothing to see here!",
|
||||
intents=discord.Intents(guilds=True, messages=True)
|
||||
)
|
||||
|
||||
# the `hidden` keyword argument hides it from the help command.
|
||||
@bot.group(hidden=True)
|
||||
|
@ -5,7 +5,10 @@ import discord
|
||||
|
||||
class Bot(commands.Bot):
|
||||
def __init__(self):
|
||||
super().__init__(command_prefix=commands.when_mentioned_or('$'))
|
||||
super().__init__(
|
||||
command_prefix=commands.when_mentioned_or('$'),
|
||||
intents=discord.Intents(guilds=True, messages=True)
|
||||
)
|
||||
|
||||
async def on_ready(self):
|
||||
print(f'Logged in as {self.user} (ID: {self.user.id})')
|
||||
|
@ -5,7 +5,10 @@ import discord
|
||||
|
||||
class CounterBot(commands.Bot):
|
||||
def __init__(self):
|
||||
super().__init__(command_prefix=commands.when_mentioned_or('$'))
|
||||
super().__init__(
|
||||
command_prefix=commands.when_mentioned_or('$'),
|
||||
intents=discord.Intents(guilds=True, messages=True)
|
||||
)
|
||||
|
||||
async def on_ready(self):
|
||||
print(f'Logged in as {self.user} (ID: {self.user.id})')
|
||||
|
@ -1,5 +1,3 @@
|
||||
import typing
|
||||
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
|
||||
@ -39,7 +37,10 @@ class DropdownView(discord.ui.View):
|
||||
|
||||
class Bot(commands.Bot):
|
||||
def __init__(self):
|
||||
super().__init__(command_prefix=commands.when_mentioned_or('$'))
|
||||
super().__init__(
|
||||
command_prefix=commands.when_mentioned_or('$'),
|
||||
intents=discord.Intents(guilds=True, messages=True)
|
||||
)
|
||||
|
||||
async def on_ready(self):
|
||||
print(f'Logged in as {self.user} (ID: {self.user.id})')
|
||||
|
@ -4,7 +4,10 @@ import discord
|
||||
|
||||
class EphemeralCounterBot(commands.Bot):
|
||||
def __init__(self):
|
||||
super().__init__(command_prefix=commands.when_mentioned_or('$'))
|
||||
super().__init__(
|
||||
command_prefix=commands.when_mentioned_or('$'),
|
||||
intents=discord.Intents(guilds=True, messages=True)
|
||||
)
|
||||
|
||||
async def on_ready(self):
|
||||
print(f'Logged in as {self.user} (ID: {self.user.id})')
|
||||
|
@ -5,7 +5,10 @@ from urllib.parse import quote_plus
|
||||
|
||||
class GoogleBot(commands.Bot):
|
||||
def __init__(self):
|
||||
super().__init__(command_prefix=commands.when_mentioned_or('$'))
|
||||
super().__init__(
|
||||
command_prefix=commands.when_mentioned_or('$'),
|
||||
intents=discord.Intents(guilds=True, messages=True)
|
||||
)
|
||||
|
||||
async def on_ready(self):
|
||||
print(f'Logged in as {self.user} (ID: {self.user.id})')
|
||||
@ -36,4 +39,4 @@ async def google(ctx: commands.Context, *, query: str):
|
||||
await ctx.send(f'Google Result for: `{query}`', view=Google(query))
|
||||
|
||||
|
||||
bot.run('token')
|
||||
bot.run()
|
||||
|
@ -29,7 +29,11 @@ class PersistentView(discord.ui.View):
|
||||
|
||||
class PersistentViewBot(commands.Bot):
|
||||
def __init__(self):
|
||||
super().__init__(command_prefix=commands.when_mentioned_or('$'))
|
||||
super().__init__(
|
||||
command_prefix=commands.when_mentioned_or('$'),
|
||||
intents=discord.Intents(guilds=True, messages=True)
|
||||
)
|
||||
|
||||
self.persistent_views_added = False
|
||||
|
||||
async def on_ready(self):
|
||||
|
@ -120,7 +120,10 @@ class TicTacToe(discord.ui.View):
|
||||
|
||||
class TicTacToeBot(commands.Bot):
|
||||
def __init__(self):
|
||||
super().__init__(command_prefix=commands.when_mentioned_or('$'))
|
||||
super().__init__(
|
||||
command_prefix=commands.when_mentioned_or('$'),
|
||||
intents=discord.Intents(guilds=True, messages=True)
|
||||
)
|
||||
|
||||
async def on_ready(self):
|
||||
print(f'Logged in as {self.user} (ID: {self.user.id})')
|
||||
|
Loading…
x
Reference in New Issue
Block a user