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