Passed
Pull Request — main (#396)
by
unknown
02:01
created

Guild.get_scheduled_events()   A

Complexity

Conditions 2

Size

Total Lines 22
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 22
rs 10
c 0
b 0
f 0
cc 2
nop 2
1
# Copyright Pincer 2021-Present
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
coding-style introduced by
Too many lines in module (2213/1000)
Loading history...
2
# Full MIT License can be found in `LICENSE` at the project root.
3
4
from __future__ import annotations
5
6
from dataclasses import dataclass, field
7
from datetime import datetime
8
from enum import IntEnum
9
from typing import AsyncGenerator, overload, TYPE_CHECKING
10
11
from aiohttp import FormData
12
13
from .channel import Channel, Thread
14
from .scheduled_events import ScheduledEvent, GuildScheduledEventUser
15
from .message.emoji import Emoji
0 ignored issues
show
introduced by
Unable to import 'pincer.objects.guild.message.emoji'
Loading history...
16
from ..message.file import File
17
from ...exceptions import UnavailableGuildError
18
from ...utils import remove_none
19
from ...utils.api_object import APIObject
20
from ...utils.types import MISSING
21
22
if TYPE_CHECKING:
23
    from typing import Any, Dict, List, Optional, Tuple, Union, Generator
24
25
    from collections.abc import AsyncIterator
26
    from .audit_log import AuditLog
27
    from .ban import Ban
28
    from .channel import ChannelType
29
    from .member import GuildMember
30
    from .features import GuildFeature
31
    from .invite import Invite
32
    from .overwrite import Overwrite
33
    from .role import Role
34
    from .scheduled_events import ScheduledEvent, GuildScheduledEventUser
0 ignored issues
show
Unused Code introduced by
The import ScheduledEvent was already done on line 14. You should be able to
remove this line.
Loading history...
Unused Code introduced by
The import GuildScheduledEventUser was already done on line 14. You should be able to
remove this line.
Loading history...
35
    from .stage import StageInstance
36
    from .template import GuildTemplate
37
    from .welcome_screen import WelcomeScreen, WelcomeScreenChannel
38
    from .widget import GuildWidget
39
    from .webhook import Webhook
40
    from ..user.user import User
41
    from ..user.integration import Integration
42
    from ..voice.region import VoiceRegion
43
    from ..events.presence import PresenceUpdateEvent
44
    from ..message.sticker import Sticker
45
    from ..user.voice_state import VoiceState
46
    from ...client import Client
47
    from ...utils.timestamp import Timestamp
48
    from ...utils.types import APINullable, JSONSerializable
49
    from ...utils.snowflake import Snowflake
50
51
52
class PremiumTier(IntEnum):
53
    """Represents the boost tier of a guild.
54
    Attributes
55
    ----------
56
    NONE:
57
        Guild has not unlocked any Server Boost perks.
58
    TIER_1:
59
        Guild has unlocked Server Boost level 1 perks.
60
    TIER_2:
61
        Guild has unlocked Server Boost level 2 perks.
62
    TIER_3:
63
        Guild has unlocked Server Boost level 3 perks.
64
    """
65
66
    NONE = 0
67
    TIER_1 = 1
68
    TIER_2 = 2
69
    TIER_3 = 3
70
71
72
class GuildNSFWLevel(IntEnum):
73
    """Represents the NSFW level of a guild.
74
    Attributes
75
    ----------
76
    DEFAULT:
77
        Default NSFW level.
78
    EXPLICIT:
79
        Explicit NSFW level.
80
    SAFE:
81
        SAFE NSFW level.
82
    AGE_RESTRICTED:
83
        Age restricted NSFW level.
84
    """
85
86
    DEFAULT = 0
87
    EXPLICIT = 1
88
    SAFE = 2
89
    AGE_RESTRICTED = 3
90
91
92
class ExplicitContentFilterLevel(IntEnum):
93
    """Represents the filter content level of a guild.
94
    Attributes
95
    ----------
96
    DISABLED:
97
        Media content will not be scanned.
98
    MEMBERS_WITHOUT_ROLES:
99
        Media content sent by members without roles will be scanned.
100
    ALL_MEMBERS:
101
        Media content sent by all members will be scanned.
102
    """
103
104
    DISABLED = 0
105
    MEMBERS_WITHOUT_ROLES = 1
106
    ALL_MEMBERS = 2
107
108
109
class MFALevel(IntEnum):
110
    """Represents the multi-factor authentication level of a guild.
111
    Attributes
112
    ----------
113
    NONE:
114
        Guild has no MFA/2FA requirement for moderation actions.
115
    ELEVATED:
116
        Guild has a 2FA requirement for moderation actions
117
    """
118
119
    NONE = 0
120
    ELEVATED = 1
121
122
123
class VerificationLevel(IntEnum):
124
    """Represents the verification level of a guild.
125
    Attributes
126
    ----------
127
    NONE:
128
        Unrestricted.
129
    LOW:
130
        Must have verified email on account.
131
    MEDIUM:
132
        Must be registered on Discord for longer than 5 minutes.
133
    HIGH:
134
        Must be a member of the server for longer than 10 minutes.
135
    VERY_HIGH:
136
        Must have a verified phone number.
137
    """
138
139
    NONE = 0
140
    LOW = 1
141
    MEDIUM = 2
142
    HIGH = 3
143
    VERY_HIGH = 4
144
145
146
class DefaultMessageNotificationLevel(IntEnum):
147
    """Represents the default message notification level of a guild.
148
    Attributes
149
    ----------
150
    ALL_MESSAGES:
151
        Members will receive notifications for all messages by default.
152
    ONLY_MENTIONS:
153
        Members will receive notifications only for messages that @mention them by default.
154
    """
155
156
    # noqa: E501
157
    ALL_MESSAGES = 0
158
    ONLY_MENTIONS = 1
159
160
161
class SystemChannelFlags(IntEnum):
162
    """Represents the system channel flags of a guild.
163
    Attributes
164
    ----------
165
    SUPPRESS_JOIN_NOTIFICATIONS:
166
        Suppress member join notifications.
167
    SUPPRESS_PREMIUM_SUBSCRIPTIONS:
168
        Suppress server boost notifications.
169
    SUPPRESS_GUILD_REMINDER_NOTIFICATIONS:
170
        Suppress server setup tips.
171
    SUPPRESS_JOIN_NOTIFICATION_REPLIES:
172
        Hide member join sticker reply buttons
173
    """
174
175
    SUPPRESS_JOIN_NOTIFICATIONS = 1 << 0
176
    SUPPRESS_PREMIUM_SUBSCRIPTIONS = 1 << 1
177
    SUPPRESS_GUILD_REMINDER_NOTIFICATIONS = 1 << 2
178
    SUPPRESS_JOIN_NOTIFICATION_REPLIES = 1 << 3
179
180
181
@dataclass(repr=False)
182
class GuildPreview(APIObject):
0 ignored issues
show
best-practice introduced by
Too many instance attributes (10/7)
Loading history...
183
    """Represents a guild preview.
184
    Attributes
185
    ----------
186
    id: :class:`Snowflake`
187
        The guild ID.
188
    name: :class:`str`
189
        The guild name.
190
    icon: :class:`str`
191
        The guild icon hash.
192
    splash: :class:`str`
193
        The guild splash hash.
194
    discovery_splash: :class:`str`
195
        The guild discovery splash hash.
196
    emojis: :class:`List[Emoji]`
197
        The guild emojis.
198
    features: :class:`List[GuildFeature]`
199
        The guild features.
200
    approximate_member_count: :class:`int`
201
        The approximate member count.
202
    approximate_presence_count: :class:`int`
203
        The approximate number of online members in this guild
204
    description: :class:`str`
205
        The guild description.
206
    """
207
208
    id: Snowflake
209
    name: str
210
    emojis: List[Emoji]
211
    features: List[GuildFeature]
212
    approximate_member_count: int
213
    approximate_presence_count: int
214
215
    icon: APINullable[str] = MISSING
216
    splash: APINullable[str] = MISSING
217
    discovery_splash: APINullable[str] = MISSING
218
    description: APINullable[str] = MISSING
219
220
221
@dataclass(repr=False)
222
class Guild(APIObject):
0 ignored issues
show
best-practice introduced by
Too many instance attributes (59/7)
Loading history...
best-practice introduced by
Too many public methods (66/20)
Loading history...
223
    """Represents a Discord guild/server in which your client resides.
224
    Attributes
225
    ----------
226
    afk_channel_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
227
        Id of afk channel
228
    afk_timeout: :class:`int`
229
        Afk timeout in seconds
230
    application_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
231
        Application id of the guild creator if it is bot-created
232
    banner: Optional[:class:`str`]
233
        Banner hash
234
    default_message_notifications: :class:`~pincer.objects.guild.guild.DefaultMessageNotificationLevel`
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (103/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
235
        Default message notifications level
236
    description: Optional[:class:`str`]
237
        The description of a Community guild
238
    discovery_splash: Optional[:class:`str`]
239
        Discovery splash hash;
240
        only present for guilds with the "DISCOVERABLE" feature
241
    emojis: List[:class:`~pincer.objects.message.emoji.Emoji`]
242
        Custom guild emojis
243
    explicit_content_filter: :class:`~pincer.objects.guild.guild.ExplicitContentFilterLevel`
244
        Explicit content filter level
245
    features: List[:class:`~pincer.objects.guild.features.GuildFeature`]
246
        Enabled guild features
247
    id: :class:`~pincer.utils.snowflake.Snowflake`
248
        Guild id
249
    icon: Optional[:class:`str`]
250
        Icon hash
251
    mfa_level: :class:`~pincer.objects.guild.guild.MFALevel`
252
        Required MFA level for the guild
253
    name: :class:`str`
254
        Guild name (2-100 characters, excluding trailing and leading
255
        whitespace)
256
    nsfw_level: :class:`~pincer.objects.guild.guild.NSFWLevel`
257
        Guild NSFW level
258
    owner_id: :class:`~pincer.utils.snowflake.Snowflake`
259
        Id of owner
260
    preferred_locale: :class:`str`
261
        The preferred locale of a Community guild;
262
        used in server discovery and notices from Discord;
263
        defaults to "en-US"
264
    premium_tier: :class:`~pincer.objects.guild.guild.PremiumTier`
265
        Premium tier (Server Boost level)
266
    public_updates_channel_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
267
        The id of the channel where admins
268
        and moderators of Community guilds receive notices from Discord
269
    roles: List[:class:`~pincer.objects.guild.role.Role`]
270
        Roles in the guild
271
    rules_channel_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
272
        The id of the channel where Community guilds can display rules
273
        and/or guidelines
274
    splash: Optional[:class:`str`]
275
        Splash hash
276
    system_channel_flags: :class:`~pincer.objects.guild.guild.SystemChannelFlags`
277
        System channel flags
278
    system_channel_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
279
        The id of the channel where guild notices
280
        such as welcome messages and boost events are posted
281
    vanity_url_code: Optional[:class:`str`]
282
        The vanity url code for the guild
283
    verification_level: :class:`~pincer.objects.guild.guild.VerificationLevel`
284
        Verification level required for the guild
285
    approximate_member_count: APINullable[:class:`int`]
286
        Approximate number of members in this guild, returned from the
287
        `GET /guilds/<id>` endpoint when with_counts is true
288
    approximate_presence_count: APINullable[:class:`int`]
289
        Approximate number of non-offline members in this guild,
290
        returned from the `GET /guilds/<id>`
291
        endpoint when with_counts is true
292
    channels: APINullable[List[:class:`~pincer.objects.guild.channel.Channel`]]
293
        Channels in the guild
294
    icon_hash: APINullable[Optional[:class:`str`]]
295
        Icon hash, returned when in the template object
296
    joined_at: APINullable[:class:`~pincer.utils.timestamp.Timestamp`]
297
        When this guild was joined at
298
    large: APINullable[:class:`bool`]
299
        True if this is considered a large guild
300
    max_members: APINullable[:class:`int`]
301
        The maximum number of members for the guild
302
    max_presences: APINullable[Optional[:class:`int`]]
303
        The maximum number of presences for the guild
304
        (null is always returned, apart from the largest of guilds)
305
    max_video_channel_users: APINullable[:class:`int`]
306
        The maximum amount of users in a video channel
307
    members: APINullable[List[:class:`~pincer.objects.guild.member.GuildMember`]]
308
        Users in the guild
309
    member_count: APINullable[:class:`bool`]
310
        Total number of members in this guild
311
    nsfw: APINullable[:class:`bool`]
312
        Boolean if the server is NSFW
313
    owner: APINullable[:class:`bool`]
314
        True if the user is the owner of the guild
315
    permissions: APINullable[:class:`str`]
316
        Total permissions for the user in the guild
317
        (excludes overwrites)
318
    premium_subscription_count: APINullable[:class:`int`]
319
        The number of boosts this guild currently has
320
    presences: APINullable[List[:class:`~pincer.objects.events.presence.PresenceUpdateEvent`]]
321
        Presences of the members in the guild,
322
        will only include non-offline members if the size is greater
323
        than large threshold
324
    stage_instances: APINullable[List[:class:`~pincer.objects.guild.stage.StageInstance`]]
325
        Stage instances in the guild
326
    stickers: Optional[List[:class:`~pincer.objects.message.sticker.Sticker`]]
327
        Custom guild stickers
328
    region: APINullable[Optional[:class:`str`]]
329
        Voice region id for the guild (deprecated)
330
    threads: APINullable[List[:class:`~pincer.objects.guild.channel.Channel`]]
331
        All active threads in the guild that current user
332
        has permission to view
333
    unavailable: APINullable[:class:`bool`]
334
        True if this guild is unavailable due to an outage
335
    voice_states: APINullable[List[:class:`~pincer.objects.user.voice_state.VoiceState`]]
336
        States of members currently in voice channels;
337
        lacks the guild_id key
338
    widget_enabled: APINullable[:class:`bool`]
339
        True if the server widget is enabled
340
    widget_channel_id: APINullable[Optional[:class:`~pincer.utils.snowflake.Snowflake`]]
341
        The channel id that the widget will generate an invite to,
342
        or null if set to no invite
343
    welcome_screen: APINullable[:class:`~pincer.objects.guild.welcome_screen.WelcomeScreen`]
344
        The welcome screen of a Community guild, shown to new members,
345
        returned in an Invite's guild object
346
    """
347
348
    # noqa: E501
349
    features: List[GuildFeature]
350
    id: Snowflake
351
    name: str
352
    nsfw_level: GuildNSFWLevel
353
    verification_level: VerificationLevel
354
355
    # Guild invites missing
356
    system_channel_flags: APINullable[SystemChannelFlags] = MISSING
357
    explicit_content_filter: APINullable[ExplicitContentFilterLevel] = MISSING
358
    premium_tier: APINullable[PremiumTier] = MISSING
359
    default_message_notifications: APINullable[
360
        DefaultMessageNotificationLevel
361
    ] = MISSING
362
    mfa_level: APINullable[MFALevel] = MISSING
363
    owner_id: APINullable[Snowflake] = MISSING
364
    afk_timeout: APINullable[int] = MISSING
365
    emojis: APINullable[List[Emoji]] = MISSING
366
    preferred_locale: APINullable[str] = MISSING
367
    roles: APINullable[List[Role]] = MISSING
368
369
    guild_scheduled_events: APINullable[List[ScheduledEvent]] = MISSING
370
    lazy: APINullable[bool] = MISSING
371
    premium_progress_bar_enabled: APINullable[bool] = MISSING
372
    guild_hashes: APINullable[Dict] = MISSING
373
    afk_channel_id: APINullable[Snowflake] = MISSING
374
    application_id: APINullable[Snowflake] = MISSING
375
    embedded_activities: APINullable[List] = MISSING
376
    banner: APINullable[str] = MISSING
377
    description: APINullable[str] = MISSING
378
    discovery_splash: APINullable[str] = MISSING
379
    icon: APINullable[str] = MISSING
380
    public_updates_channel_id: APINullable[Snowflake] = MISSING
381
    rules_channel_id: APINullable[Snowflake] = MISSING
382
    splash: APINullable[str] = MISSING
383
    system_channel_id: APINullable[Snowflake] = MISSING
384
    vanity_url_code: APINullable[str] = MISSING
385
386
    application_command_counts: APINullable[Dict] = MISSING
387
    application_command_count: APINullable[int] = MISSING
388
    approximate_member_count: APINullable[int] = MISSING
389
    approximate_presence_count: APINullable[int] = MISSING
390
    channels: APINullable[List[Channel]] = field(default_factory=list)
391
    # TODO: Add type when type is known
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
392
    hub_type: APINullable[Any] = MISSING
393
    icon_hash: APINullable[Optional[str]] = MISSING
394
    joined_at: APINullable[Timestamp] = MISSING
395
    large: APINullable[bool] = MISSING
396
    max_members: APINullable[int] = MISSING
397
    max_presences: APINullable[Optional[int]] = MISSING
398
    max_video_channel_users: APINullable[int] = MISSING
399
    members: APINullable[List[GuildMember]] = MISSING
400
    member_count: APINullable[bool] = MISSING
401
    nsfw: APINullable[bool] = MISSING
402
    # Note: This is missing from discord's docs but in the api
403
    owner: APINullable[bool] = MISSING
404
    permissions: APINullable[str] = MISSING
405
    premium_subscription_count: APINullable[int] = MISSING
406
    presences: APINullable[List[PresenceUpdateEvent]] = MISSING
407
    stage_instances: APINullable[List[StageInstance]] = MISSING
408
    stickers: APINullable[List[Sticker]] = MISSING
409
    region: APINullable[Optional[str]] = MISSING
410
    threads: APINullable[List[Channel]] = MISSING
411
    # Guilds are considered available unless otherwise specified
412
    unavailable: APINullable[bool] = False
413
    voice_states: APINullable[List[VoiceState]] = MISSING
414
    widget_enabled: APINullable[bool] = MISSING
415
    widget_channel_id: APINullable[Optional[Snowflake]] = MISSING
416
    welcome_screen: APINullable[WelcomeScreen] = MISSING
417
418
    @classmethod
419
    async def from_id(
420
        cls,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
421
        client: Client,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
422
        _id: Union[int, Snowflake],
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
423
        with_counts: bool = False,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
424
    ) -> Guild:
425
        """
426
        Parameters
427
        ----------
428
        client : :class:`~pincer.Client`
429
            Client object to use the http gateway from.
430
        _id : :class:`~pincer.utils.snowflake.Snowflake`
431
            Guild ID.
432
        Returns
433
        -------
434
        :class:`~pincer.objects.guild.guild.Guild`
435
            The new guild object.
436
        """
437
        data = await client.http.get(
438
            f"/guilds/{_id}",
439
            # Yarl don't support boolean params
440
            params={"with_counts": "true" if with_counts else None},
441
        )
442
        channel_data = await client.http.get(f"/guilds/{_id}/channels")
443
444
        data["channels"]: List[Channel] = [
445
            Channel.from_dict(i) for i in (channel_data or [])
446
        ]
447
448
        return Guild.from_dict(data)
449
450
    async def get_member(self, _id: int) -> GuildMember:
451
        """|coro|
452
        Fetches a GuildMember from its identifier
453
454
        Parameters
455
        ----------
456
        _id: int
457
            The id of the guild member which should be fetched from the Discord
458
            gateway.
459
        Returns
460
        -------
461
        :class:`~pincer.objects.guild.member.GuildMember`
462
            A GuildMember object.
463
        """
464
        return await GuildMember.from_id(self._client, self.id, _id)
465
466
    @overload
467
    async def modify_member(
468
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
469
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
470
        _id: int,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
471
        nick: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
472
        roles: Optional[List[Snowflake]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
473
        mute: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
474
        deaf: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
475
        channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
476
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
477
        communication_disabled_until: Optional[Timestamp] = MISSING,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
478
    ) -> GuildMember:
479
        """|coro|
480
        Modifies a member in the guild from its identifier and based on the
481
        keyword arguments provided.
482
        Parameters
483
        ----------
484
        _id : int
485
            Id of the member to modify
486
        nick : Optional[:class:`str`]
487
            New nickname for the member |default| :data:`None`
488
        roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake]]
489
            New roles for the member |default| :data:`None`
490
        mute : Optional[:class:`bool`]
491
            Whether the member is muted |default| :data:`None`
492
        deaf : Optional[:class:`bool`]
493
            Whether the member is deafened |default| :data:`None`
494
        channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake]
495
            Voice channel id to move to |default| :data:`None`
496
        reason : Optional[:class:`str`]
497
            audit log reason |default| :data:`None`
498
        communication_disabled_until : Optional[Timestamp]
499
            When the member can communicate again, requires ``MODERATE_MEMBERS``
500
            permissions. Set to ``None`` to disable the timeout.
501
502
        Returns
503
        -------
504
        :class:`~pincer.objects.guild.member.GuildMember`
505
            The new member object.
506
        """
507
        ...
508
509
    async def modify_member(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
510
        self, _id: int, reason=None, **kwargs
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
511
    ) -> GuildMember:
512
        if kwargs.get("communication_disabled_until") is MISSING:
513
            kwargs.pop("communication_disabled_until")
514
        data = await self._http.patch(
515
            f"guilds/{self.id}/members/{_id}",
516
            data=kwargs,
517
            headers={"X-Audit-Log-Reason": reason},
518
        )
519
        return GuildMember.from_dict(data)
520
521
    @overload
522
    async def create_channel(
523
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
524
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
525
        name: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
526
        type: Optional[ChannelType] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
Bug Best Practice introduced by
This seems to re-define the built-in type.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
527
        topic: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
528
        bitrate: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
529
        user_limit: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
530
        rate_limit_per_user: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
531
        position: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
532
        permission_overwrites: Optional[List[Overwrite]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
533
        parent_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
534
        nsfw: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
535
    ) -> Channel:
536
        """|coro|
537
        Create a new channel object for the guild.
538
539
        Parameters
540
        ----------
541
        name : str
542
            channel name (1-100 characters)
543
        type : Optional[:class:int`]
544
            the type of channel
545
        topic : Optional[:class:str`]
546
            channel topic (0-1024 characters)
547
        bitrate : Optional[:class:`int`]
548
            the bitrate (in bits) of the voice channel (voice only)
549
        user_limit : Optional[:class:`int`]
550
            the user limit of the voice channel (voice only)
551
        rate_limit_per_user : Optional[:class:`int`]
552
            amount of seconds a user has to wait
553
            before sending another message (0-21600)
554
            bots, as well as users with the permission
555
            manage_messages or manage_channel, are unaffected
556
        position : Optional[:class:`int`]
557
            sorting position of the channel
558
        permission_overwrites : Optional[List[:class:`~pincer.objects.guild.overwrite.Overwrite`]]
559
            the channel's permission overwrites
560
        parent_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
561
            id of the parent category for a channel
562
        nsfw : Optional[:class:`bool`]
563
            whether the channel is nsfw
564
        reason : Optional[:class:`str`]
565
            audit log reason |default| :data:`None`
566
        Returns
567
        -------
568
        :class:`~pincer.objects.guild.channel.Channel`
569
            The new channel object.
570
        """
571
        ...
572
573
    async def create_channel(self, *, reason: Optional[str] = None, **kwargs):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
574
        data = await self._http.post(
575
            f"guilds/{self.id}/channels",
576
            data=kwargs,
577
            headers={"X-Audit-Log-Reason": reason},
578
        )
579
        return Channel.from_dict(data)
580
581
    async def modify_channel_positions(
0 ignored issues
show
introduced by
Keyword argument before variable positional arguments list in the definition of modify_channel_positions function
Loading history...
582
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
583
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
584
        *channel: Dict[str, Optional[Union[int, bool, Snowflake]]],
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
585
    ):
586
        """|coro|
587
        Create a new channel object for the guild.
588
589
        Parameters
590
        ----------
591
        reason : Optional[:class:`str`]
592
            audit log reason |default| :data:`None`
593
        \\*channel : Dict[str, Optional[Union[int, bool, :class:`~pincer.utils.snowflake.Snowflake`]
594
            Keys:
595
                - id : :class:`~pincer.utils.snowflake.Snowflake`
596
                - position : Optional[:class:`int`]
597
                - lock_permissions : Optional[:class:`bool`]
598
                - parent_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
599
        """
600
        await self._http.patch(
601
            f"guilds/{self.id}/channels",
602
            data=channel,
603
            headers={"X-Audit-Log-Reason": reason},
604
        )
605
606
    async def list_active_threads(
607
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
608
    ) -> Tuple[Generator[Thread], Generator[GuildMember]]:
609
        """|coro|
610
        Returns all active threads in the guild,
611
        including public and private threads.
612
613
        Returns
614
        -------
615
        Generator[Union[:class:`~pincer.objects.guild.channel.PublicThread`, :class:`~pincer.objects.guild.channel.PrivateThread`]], Generator[:class:`~pincer.objects.guild.member.GuildMember`]]
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (194/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
616
            The new member object.
617
        """
618
        data = await self._http.get(f"guilds/{self.id}/threads/active")
619
620
        threads = (Channel.from_dict(channel) for channel in data["threads"])
621
        members = (GuildMember.from_dict(member) for member in data["members"])
622
623
        return threads, members
624
625
    async def list_guild_members(
626
        self, limit: int = 1, after: int = 0
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
627
    ) -> AsyncIterator[GuildMember]:
0 ignored issues
show
introduced by
Value 'AsyncIterator' is unsubscriptable
Loading history...
628
        """|coro|
629
        Returns a list of guild member objects that are members of the guild.
630
631
        Parameters
632
        ----------
633
        limit : int
634
            max number of members to return (1-1000) |default| :data:`1`
635
        after : int
636
            the highest user id in the previous page |default| :data:`0`
637
638
        Yields
639
        ------
640
        :class:`~pincer.objects.guild.member.GuildMember`
641
            the guild member object that is in the guild
642
        """
643
644
        members = await self._http.get(
645
            f"guilds/{self.id}/members", params={"limit": limit, "after": after}
646
        )
647
648
        for member in members:
649
            yield GuildMember.from_dict(member)
650
651
    async def search_guild_members(
652
        self, query: str, limit: Optional[int] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
653
    ) -> AsyncIterator[GuildMember]:
0 ignored issues
show
introduced by
Value 'AsyncIterator' is unsubscriptable
Loading history...
654
        """|coro|
655
        Returns a list of guild member objects whose
656
        username or nickname starts with a provided string.
657
658
        Parameters
659
        ----------
660
        query : str
661
            Query string to match username(s) and nickname(s) against.
662
        limit : Optional[int]
663
            max number of members to return (1-1000) |default| :data:`1`
664
665
        Yields
666
        -------
667
        :class:`~pincer.objects.guild.member.GuildMember`
668
            guild member objects
669
        """
670
671
        data = await self._http.get(
672
            f"guilds/{self.id}/members/search",
673
            params={"query": query, "limit": limit},
674
        )
675
676
        for member in data:
677
            yield GuildMember.from_dict(member)
678
679
    @overload
680
    async def add_guild_member(
681
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
682
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
683
        user_id: Snowflake,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
684
        access_token: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
685
        nick: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
686
        roles: Optional[List[Snowflake]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
687
        mute: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
688
        deaf: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
689
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
690
    ) -> Optional[GuildMember]:
691
        """|coro|
692
        Adds a user to the guild, provided you have a
693
        valid oauth2 access token for the user with the guilds.join scope.
694
695
        Parameters
696
        ----------
697
        user_id : str
698
            id of the user to be added
699
        access_token : str
700
            an oauth2 access token granted with the guilds.join to
701
            the bot's application for the user you want to add to the guild
702
        nick : Optional[str]
703
            value to set users nickname to
704
        roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake`]]
705
            array of role ids the member is assigned
706
        mute : Optional[bool]
707
            whether the user is muted in voice channels
708
        deaf : Optional[bool]
709
            whether the user is deafened in voice channels
710
        reason : Optional[:class:`str`]
711
            audit log reason |default| :data:`None`
712
        Returns
713
        -------
714
        :class:`~pincer.objects.guild.member.GuildMember`
715
            If the user is not in the guild
716
        None
717
            If the user is in the guild
718
        """
719
720
    async def add_guild_member(self, user_id, reason=None, **kwargs):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
721
        data = await self._http.put(
722
            f"guilds/{self.id}/members/{user_id}",
723
            data=kwargs,
724
            headers={"X-Audit-Log-Reason": reason},
725
        )
726
727
        return GuildMember.from_dict(data) if data else None
728
729
    async def modify_current_member(
730
        self, nick: str, reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
731
    ) -> GuildMember:
732
        """|coro|
733
        Modifies the current member in a guild.
734
735
        Parameters
736
        ----------
737
        nick : str
738
            value to set users nickname to
739
        reason : Optional[:class:`str`]
740
            audit log reason |default| :data:`None`
741
        Returns
742
        -------
743
        class:`~pincer.objects.guild.member.GuildMember
744
            current guild member
745
        """
746
        data = self._http.patch(
747
            f"guilds/{self.id}/members/@me",
748
            {"nick": nick},
749
            headers={"X-Audit-Log-Reason": reason},
750
        )
751
        return GuildMember.from_dict(data)
752
753
    async def add_guild_member_role(
754
        self, user_id: int, role_id: int, reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
755
    ) -> None:
756
        """|coro|
757
        Adds a role to a guild member.
758
759
        Parameters
760
        ----------
761
        user_id : int
762
            id of the user to give a role to
763
        role_id : int
764
            id of a role
765
        reason : Optional[:class:`str`]
766
            audit log reason |default| :data:`None`
767
        """
768
        data = await self._http.put(
0 ignored issues
show
Unused Code introduced by
The variable data seems to be unused.
Loading history...
769
            f"guilds/{self.id}/{user_id}/roles/{role_id}",
770
            headers={"X-Audit-Log-Reason": reason},
771
        )
772
773
    async def remove_guild_member_role(
774
        self, user_id: int, role_id: int, reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
775
    ):
776
        """|coro|
777
        Removes a role from a guild member.
778
779
        Parameters
780
        ----------
781
        user_id : int
782
            id of the user to remove a role from
783
        role_id : int
784
            id of a role
785
        reason : Optional[:class:`str`]
786
            audit log reason |default| :data:`None`
787
        """
788
        await self._http.delete(
789
            f"guilds/{self.id}/{user_id}/roles/{role_id}",
790
            headers={"X-Audit-Log-Reason": reason},
791
        )
792
793
    async def remove_guild_member(
794
        self, user_id: int, reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
795
    ):
796
        """|coro|
797
        Remove a member from a guild.
798
799
        Parameters
800
        ----------
801
        user_id : int
802
            id of the user to remove from the guild
803
        reason : Optional[:class:`str`]
804
            audit log reason |default| :data:`None`
805
        """
806
        await self._http.delete(
807
            f"guilds/{self.id}/members/{user_id}",
808
            headers={"X-Audit-Log-Reason": reason},
809
        )
810
811
    async def ban(
812
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
813
        member_id: int,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
814
        reason: str = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
815
        delete_message_days: int = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
816
    ):
817
        """
818
        Parameters
819
        ----------
820
        member_id : :class:`int`
821
            ID of the guild member to ban.
822
        reason : Optional[:class:`str`]
823
            Reason for the kick.
824
        delete_message_days : Optional[:class:`int`]
825
            Number of days to delete messages for (0-7)
826
        """
827
        headers = {}
828
829
        if reason is not None:
830
            headers["X-Audit-Log-Reason"] = reason
831
832
        data = {}
833
834
        if delete_message_days is not None:
835
            data["delete_message_days"] = delete_message_days
836
837
        await self._http.put(
838
            f"/guilds/{self.id}/bans/{member_id}", data=data, headers=headers
839
        )
840
841
    async def kick(self, member_id: int, reason: Optional[str] = None):
842
        """|coro|
843
        Kicks a guild member.
844
        Parameters
845
        ----------
846
        member_id : :class:`int`
847
            ID of the guild member to kick.
848
        reason : Optional[:class:`str`]
849
            Reason for the kick.
850
        """
851
852
        headers = {}
853
854
        if reason is not None:
855
            headers["X-Audit-Log-Reason"] = reason
856
857
        await self._http.delete(
858
            f"/guilds/{self.id}/members/{member_id}", headers=headers
859
        )
860
861
    async def get_roles(self) -> AsyncGenerator[Role, None]:
862
        """|coro|
863
        Fetches all the roles in the guild.
864
865
        Yields
866
        -------
867
        AsyncGenerator[:class:`~pincer.objects.guild.role.Role`, :data:`None`]
868
            An async generator of Role objects.
869
        """
870
        data = await self._http.get(f"guilds/{self.id}/roles")
871
        for role_data in data:
872
            yield Role.from_dict(role_data)
873
874
    @overload
875
    async def create_role(
876
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
877
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
878
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
879
        name: Optional[str] = "new role",
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
880
        permissions: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
881
        color: Optional[int] = 0,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
882
        hoist: Optional[bool] = False,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
883
        icon: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
884
        unicode_emoji: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
885
        mentionable: Optional[bool] = False,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
886
    ) -> Role:
887
        """|coro|
888
        Creates a new role for the guild.
889
        Requires the ``MANAGE_ROLES`` permission.
890
891
        Parameters
892
        ----------
893
        reason : Optional[:class:`str`]
894
            Reason for creating the role. |default| :data:`None`
895
        name : Optional[:class:`str`]
896
            name of the role |default| :data:`"new role"`
897
        permissions : Optional[:class:`str`]
898
            bitwise value of the enabled/disabled
899
            permissions, set to @everyone permissions
900
            by default |default| :data:`None`
901
        color : Optional[:class:`int`]
902
            RGB color value |default| :data:`0`
903
        hoist : Optional[:class:`bool`]
904
            whether the role should be displayed
905
            separately in the sidebar |default| :data:`False`
906
        icon : Optional[:class:`str`]
907
            the role's icon image (if the guild has
908
            the ``ROLE_ICONS`` feature) |default| :data:`None`
909
        unicode_emoji : Optional[:class:`str`]
910
            the role's unicode emoji as a standard emoji (if the guild
911
            has the ``ROLE_ICONS`` feature) |default| :data:`None`
912
        mentionable : Optional[:class:`bool`]
913
            whether the role should be mentionable |default| :data:`False`
914
915
        Returns
916
        -------
917
        :class:`~pincer.objects.guild.role.Role`
918
            The new role object.
919
        """
920
        ...
921
922
    async def create_role(self, reason: Optional[str] = None, **kwargs) -> Role:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
923
        return Role.from_dict(
924
            await self._http.post(
925
                f"guilds/{self.id}/roles",
926
                data=kwargs,
927
                headers={"X-Audit-Log-Reason": reason},
928
            )
929
        )
930
931
    async def edit_role_position(
932
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
933
        id: Snowflake,
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in id.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
934
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
935
        position: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
936
    ) -> AsyncGenerator[Role, None]:
937
        """|coro|
938
        Edits the position of a role.
939
940
        Parameters
941
        ----------
942
        id : :class:`~pincer.utils.snowflake.Snowflake`
943
            The role ID
944
        reason : Optional[:class:`str`]
945
            Reason for editing the role position. |default| :data:`None`
946
        position : Optional[:class:`int`]
947
            Sorting position of the role |default| :data:`None`
948
949
        Yields
950
        -------
951
        AsyncGenerator[:class:`~pincer.objects.guild.role.Role`, :data:`None`]
952
            An async generator of all the guild's role objects.
953
        """
954
        data = await self._http.patch(
955
            f"guilds/{self.id}/roles",
956
            data={"id": id, "position": position},
957
            headers={"X-Audit-Log-Reason": reason},
958
        )
959
        for role_data in data:
960
            yield Role.from_dict(role_data)
961
962
    @overload
963
    async def edit_role(
964
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
965
        id: Snowflake,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
Bug Best Practice introduced by
This seems to re-define the built-in id.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
966
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
967
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
968
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
969
        permissions: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
970
        color: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
971
        hoist: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
972
        icon: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
973
        unicode_emoji: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
974
        mentionable: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
975
    ) -> Role:
976
        """|coro|
977
        Edits a role.
978
        Requires the ``MANAGE_ROLES`` permission.
979
980
        Parameters
981
        ----------
982
        id : :class:`~pincer.utils.snowflake.Snowflake`
983
            The role ID
984
        reason : Optional[:class:`str`]
985
            Reason for editing the role |default| :data:`None`
986
        name : Optional[:class:`str`]
987
            Name of the role |default| :data:`None`
988
        permissions : Optional[:class:`str`]
989
            Bitwise value of the enabled/disabled
990
            permissions |default| :data:`None`
991
        color : Optional[:class:`int`]
992
            RGB color value |default| :data:`None`
993
        hoist : Optional[:class:`bool`]
994
            Whether the role should be displayed
995
            separately in the sidebar |default| :data:`None`
996
        icon : Optional[:class:`str`]
997
            The role's icon image (if the guild has
998
            the ``ROLE_ICONS`` feature) |default| :data:`None`
999
        unicode_emoji : Optional[:class:`str`]
1000
            The role's unicode emoji as a standard emoji (if the guild
1001
            has the ``ROLE_ICONS`` feature) |default| :data:`None`
1002
        mentionable : Optional[:class:`bool`]
1003
            Whether the role should be mentionable |default| :data:`None`
1004
1005
        Returns
1006
        -------
1007
        :class:`~pincer.objects.guild.role.Role`
1008
            The edited role object.
1009
        """
1010
        ...
1011
1012
    async def edit_role(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
1013
        self, id: Snowflake, reason: Optional[str] = None, **kwargs
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in id.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1014
    ) -> Role:
1015
        return Role.from_dict(
1016
            await self._http.patch(
1017
                f"guilds/{self.id}/roles/{id}",
1018
                data=kwargs,
1019
                headers={"X-Audit-Log-Reason": reason},
1020
            )
1021
        )
1022
1023
    async def delete_role(self, id: Snowflake, reason: Optional[str] = None):
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in id.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
1024
        """|coro|
1025
        Deletes a role.
1026
        Requires the `MANAGE_ROLES` permission.
1027
1028
        Parameters
1029
        ----------
1030
        id : :class:`~pincer.utils.snowflake.Snowflake`
1031
            The role ID
1032
        reason : Optional[:class:`str`]
1033
            The reason for deleting the role |default| :data:`None`
1034
        """
1035
        await self._http.delete(
1036
            f"guilds/{self.id}/roles/{id}",
1037
            headers={"X-Audit-Log-Reason": reason},
1038
        )
1039
1040
    async def get_bans(self) -> AsyncGenerator[Ban, None]:
1041
        """|coro|
1042
        Fetches all the bans in the guild.
1043
1044
        Yields
1045
        -------
1046
        AsyncGenerator[:class:`~pincer.objects.guild.ban.Ban`, :data:`None`]
1047
            An async generator of Ban objects.
1048
        """
1049
        data = await self._http.get(f"guilds/{self.id}/bans")
1050
        for ban_data in data:
1051
            yield Ban.from_dict(ban_data)
1052
1053
    async def get_ban(self, id: Snowflake) -> Ban:
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in id.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
1054
        """|coro|
1055
        Fetches a ban from the guild.
1056
1057
        Parameters
1058
        ----------
1059
        id : :class:`~pincer.utils.snowflake.Snowflake`
1060
            The user ID
1061
1062
        Returns
1063
        -------
1064
        :class:`~pincer.objects.guild.ban.Ban`
1065
            The Ban object.
1066
        """
1067
        return Ban.from_dict(
1068
            await self._http.get(f"guilds/{self.id}/bans/{id}")
1069
        )
1070
1071
    async def unban(self, id: Snowflake, reason: Optional[str] = None):
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in id.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
1072
        """|coro|
1073
        Unbans a user from the guild.
1074
1075
        Parameters
1076
        ----------
1077
        id : :class:`~pincer.utils.snowflake.Snowflake`
1078
            The user ID
1079
        reason : Optional[:class:`str`]
1080
            The reason for unbanning the user |default| :data:`None`
1081
        """
1082
        await self._http.delete(
1083
            f"guilds/{self.id}/bans/{id}",
1084
            headers={"X-Audit-Log-Reason": reason},
1085
        )
1086
1087
    @overload
1088
    async def edit(
0 ignored issues
show
Comprehensibility introduced by
This function exceeds the maximum number of variables (20/15).
Loading history...
1089
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1090
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1091
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1092
        region: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1093
        verification_level: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1094
        default_message_notifications: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1095
        explicit_content_filter: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1096
        afk_channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1097
        afk_timeout: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1098
        icon: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1099
        owner_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1100
        splash: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1101
        discovery_splash: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1102
        banner: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1103
        system_channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1104
        system_channel_flags: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1105
        rules_channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1106
        public_updates_channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1107
        preferred_locale: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1108
        features: Optional[List[GuildFeature]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1109
        description: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1110
    ) -> Guild:
1111
        """|coro|
1112
        Modifies the guild
1113
1114
        Parameters
1115
        ----------
1116
        name : Optional[:class:`str`]
1117
            Guild name |default| :data:`None`
1118
        region : Optional[:class:`str`]
1119
            Guild voice region ID |default| :data:`None`
1120
        verification_level : Optional[:class:`int`]
1121
            Verification level |default| :data:`None`
1122
        default_message_notifications : Optional[:class:`int`]
1123
            Default message notification level |default| :data:`None`
1124
        explicit_content_filter : Optional[:class:`int`]
1125
            Explicit content filter level |default| :data:`None`
1126
        afk_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
1127
            ID for AFK channel |default| :data:`None`
1128
        afk_timeout : Optional[:class:`int`]
1129
            AFK timeout in seconds |default| :data:`None`
1130
        icon : Optional[:class:`str`]
1131
            base64 1024x1024 png/jpeg/gif image for the guild icon
1132
            (can be animated gif when the server
1133
            has the `ANIMATED_ICON` feature) |default| :data:`None`
1134
        owner_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
1135
            User ID to transfer guild ownership to (must be owner) |default| :data:`None`
1136
        splash : Optional[:class:`str`]
1137
            base64 16:9 png/jpeg image for the guild splash (when the
1138
            server has the `INVITE_SPLASH` feature) |default| :data:`None`
1139
        discovery_splash : Optional[:class:`str`]
1140
            base64 16:9 png/jpeg image for the guild discovery splash
1141
            (when the server has the `DISCOVERABLE` feature) |default| :data:`None`
1142
        banner : Optional[:class:`str`]
1143
            base64 16:9 png/jpeg image for the guild banner (when the
1144
            server has the `BANNER` feature) |default| :data:`None`
1145
        system_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
1146
            The ID of the channel where guild notices such as welcome
1147
            messages and boost events are posted |default| :data:`None`
1148
        system_channel_flags : Optional[:class:`int`]
1149
            System channel flags |default| :data:`None`
1150
        rules_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
1151
            The ID of the channel where Community guilds display rules
1152
            and/or guidelines |default| :data:`None`
1153
        public_updates_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
1154
            The ID of the channel where admins and moderators of
1155
            Community guilds receive notices from Discord |default| :data:`None`
1156
        preferred_locale : Optional[:class:`str`]
1157
            The preferred locale of a Community guild used in server
1158
            discovery and notices from Discord; defaults to "en-US" |default| :data:`None`
1159
        features : Optional[List[:class:`GuildFeature`]]
1160
            Enabled guild features |default| :data:`None`
1161
        description : Optional[:class:`str`]
1162
            The description for the guild, if the guild is discoverable |default| :data:`None`
1163
1164
        Returns
1165
        -------
1166
        :class:`~pincer.objects.guild.Guild`
1167
            The modified guild object.
1168
        """
1169
        ...
1170
1171
    async def edit(self, **kwargs) -> Guild:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
1172
        g = await self._http.patch(f"guilds/{self.id}", data=kwargs)
1173
        return Guild.from_dict(g)
1174
1175
    async def preview(self) -> GuildPreview:
1176
        """|coro|
1177
        Previews the guild.
1178
1179
        Returns
1180
        -------
1181
        :class:`~pincer.objects.guild.guild.GuildPreview`
1182
            The guild preview object.
1183
        """
1184
        data = await self._http.get(f"guilds/{self.id}/preview")
1185
        return GuildPreview.from_dict(data)
1186
1187
    async def delete(self):
1188
        """|coro|
1189
        Deletes the guild. Returns `204 No Content` on success.
1190
        """
1191
        await self._http.delete(f"guilds/{self.id}")
1192
1193
    async def prune_count(
1194
        self, days: Optional[int] = 7, include_roles: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1195
    ) -> int:
1196
        """|coro|
1197
        Returns the number of members that
1198
        would be removed in a prune operation.
1199
        Requires the ``KICK_MEMBERS`` permission.
1200
1201
        Parameters
1202
        ----------
1203
        days : Optional[:class:`int`]
1204
            Number of days to count prune for (1-30) |default| :data:`7`
1205
        include_roles : Optional[:class:`str`]
1206
            Comma-delimited array of Snowflakes;
1207
            role(s) to include |default| :data:`None`
1208
1209
        Returns
1210
        -------
1211
        :class:`int`
1212
            The number of members that would be removed.
1213
        """
1214
        return await self._http.get(
1215
            f"guilds/{self.id}/prune",
1216
            params={"days": days, "include_roles": include_roles},
1217
        )["pruned"]
1218
1219
    async def prune(
1220
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1221
        days: Optional[int] = 7,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1222
        compute_prune_days: Optional[bool] = True,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1223
        include_roles: Optional[List[Snowflake]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1224
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1225
    ) -> int:
1226
        """|coro|
1227
        Prunes members from the guild. Requires the ``KICK_MEMBERS`` permission.
1228
1229
        Parameters
1230
1231
        Parameters
1232
        ----------
1233
        days : Optional[:class:`int`]
1234
            Number of days to prune (1-30) |default| :data:`7`
1235
        compute_prune_days : Optional[:class:`bool`]
1236
            Whether ``pruned`` is returned, discouraged for large guilds
1237
            |default| :data:`True`
1238
        include_roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake`]]
1239
            role(s) to include |default| :data:`None`
1240
        reason : Optional[:class:`str`]
1241
            Reason for the prune |default| :data:`None`
1242
1243
        Returns
1244
        -------
1245
        :class:`int`
1246
            The number of members that were removed.
1247
        """
1248
        return await self._http.post(
1249
            f"guilds/{self.id}/prune",
1250
            data={
1251
                "days": days,
1252
                "compute_prune_days": compute_prune_days,
1253
                "include_roles": include_roles,
1254
            },
1255
            headers={"X-Audit-Log-Reason": reason},
1256
        )["pruned"]
1257
1258
    async def get_voice_regions(self) -> AsyncGenerator[VoiceRegion, None]:
1259
        """|coro|
1260
        Returns an async generator of voice regions.
1261
1262
        Yields
1263
        -------
1264
        AsyncGenerator[:class:`~pincer.objects.voice.VoiceRegion`, :data:`None`]
1265
            An async generator of voice regions.
1266
        """
1267
        data = await self._http.get(f"guilds/{self.id}/regions")
1268
        for voice_region_data in data:
1269
            yield VoiceRegion.from_dict(voice_region_data)
1270
1271
    async def get_invites(self) -> AsyncGenerator[Invite, None]:
1272
        """|coro|
1273
        Returns an async generator of invites for the guild.
1274
        Requires the ``MANAGE_GUILD`` permission.
1275
1276
        Yields
1277
        -------
1278
        AsyncGenerator[:class:`~pincer.objects.invite.Invite`, :data:`None`]
1279
            An async generator of invites.
1280
        """
1281
        data = await self._http.get(f"guilds/{self.id}/invites")
1282
        for invite_data in data:
1283
            yield Invite.from_dict(invite_data)
1284
1285
    async def get_invite(self, code: str) -> Invite:
1286
        """|coro|
1287
        Returns an Invite object for the given invite code.
1288
1289
        Parameters
1290
        ----------
1291
        code : :class:`str`
1292
            The invite code to get the invite for.
1293
1294
        Returns
1295
        -------
1296
        :class:`~pincer.objects.guild.invite.Invite`
1297
            The invite object.
1298
        """
1299
        data = await self._http.get(f"invite/{code}")
1300
        return Invite.from_dict(data)
1301
1302
    async def get_integrations(self) -> AsyncIterator[Integration]:
0 ignored issues
show
introduced by
Value 'AsyncIterator' is unsubscriptable
Loading history...
1303
        """|coro|
1304
        Returns an async generator of integrations for the guild.
1305
        Requires the ``MANAGE_GUILD`` permission.
1306
1307
        Yields
1308
        -------
1309
        AsyncGenerator[:class:`~pincer.objects.integration.Integration`, :data:`None`]
1310
            An async generator of integrations.
1311
        """
1312
        data = await self._http.get(f"guilds/{self.id}/integrations")
1313
        for integration_data in data:
1314
            yield Integration.from_dict(integration_data)
1315
1316
    async def delete_integration(
1317
        self, integration: Integration, reason: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1318
    ):
1319
        """|coro|
1320
        Deletes an integration.
1321
        Requires the ``MANAGE_GUILD`` permission.
1322
1323
        Parameters
1324
        ----------
1325
        integration : :class:`~pincer.objects.integration.Integration`
1326
            The integration to delete.
1327
        reason : Optional[:class:`str`]
1328
            Reason for the deletion |default| :data:`None`
1329
        """
1330
        await self._http.delete(
1331
            f"guilds/{self.id}/integrations/{integration.id}",
1332
            headers={"X-Audit-Log-Reason": reason},
1333
        )
1334
1335
    async def delete_invite(self, code: str):
1336
        """|coro|
1337
        Deletes an invite.
1338
        Requires the ``MANAGE_GUILD`` intent.
1339
1340
        Parameters
1341
        ----------
1342
        code : :class:`str`
1343
            The code of the invite to delete.
1344
        """
1345
        await self._http.delete(f"guilds/{self.id}/invites/{code}")
1346
1347
    async def get_widget_settings(self) -> GuildWidget:
1348
        """|coro|
1349
        Returns the guild widget settings.
1350
        Requires the ``MANAGE_GUILD`` permission.
1351
1352
        Returns
1353
        -------
1354
        :class:`~pincer.objects.guild.widget.GuildWidget`
1355
            The guild widget settings.
1356
        """
1357
        return GuildWidget.from_dict(
1358
            await self._http.get(f"guilds/{self.id}/widget")
1359
        )
1360
1361
    async def modify_widget(
1362
        self, reason: Optional[str] = None, **kwargs
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1363
    ) -> GuildWidget:
1364
        """|coro|
1365
        Modifies the guild widget for the guild.
1366
        Requires the ``MANAGE_GUILD`` permission.
1367
1368
        Parameters
1369
        ----------
1370
        reason : Optional[:class:`str`]
1371
            Reason for the modification |default| :data:`None`
1372
        \\*\\*kwargs
1373
            The widget settings to modify
1374
1375
        Returns
1376
        -------
1377
        :class:`~pincer.objects.guild.widget.GuildWidget`
1378
            The updated GuildWidget object
1379
        """
1380
        data = await self._http.patch(
1381
            f"guilds/{self.id}/widget",
1382
            data=kwargs,
1383
            headers={"X-Audit-Log-Reason": reason},
1384
        )
1385
        return GuildWidget.from_dict(data)
1386
1387
    async def get_widget(self) -> Dict[str, JSONSerializable]:
1388
        """|coro|
1389
        Returns the widget for the guild
1390
        """
1391
        return await self._http.get(f"guilds/{self.id}/widget.json")
1392
1393
    @property
1394
    async def vanity_url(self) -> Invite:
1395
        """|coro|
1396
        Returns the Vanity URL for the guild.
1397
        Requires the ``MANAGE_GUILD`` permission.
1398
        ``code`` will be null if a vanity URL has not been set.
1399
1400
        Returns
1401
        -------
1402
        :class:`~pincer.objects.guild.invite.Invite`
1403
            The vanity url for the guild.
1404
        """
1405
        data = await self._http.get(f"guilds/{self.id}/vanity-url")
1406
        return Invite.from_dict(data)
1407
1408
    async def get_widget_image(
1409
        self, style: Optional[str] = "shield"
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1410
    ) -> str:  # TODO Replace str with ImageURL object
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
1411
        """|coro|
1412
        Returns a PNG image widget for the guild.
1413
        Requires no permissions or authentication.
1414
1415
        Widget Style Options
1416
        -------------------
1417
        * [``shield``](https://discord.com/api/guilds/81384788765712384/widget.png?style=shield)
1418
          shield style widget with Discord icon and guild members online count
1419
        * [``banner1``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner1)
1420
          large image with guild icon, name and online count.
1421
          "POWERED BY DISCORD" as the footer of the widget
1422
        * [``banner2``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner2)
1423
          smaller widget style with guild icon, name and online count.
1424
          Split on the right with Discord logo
1425
        * [``banner3``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner3)
1426
          large image with guild icon, name and online count.
1427
          In the footer, Discord logo on the
1428
          left and "Chat Now" on the right
1429
        * [``banner4``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner4)
1430
          large Discord logo at the top of the widget.
1431
          Guild icon, name and online count in the middle portion
1432
          of the widget and a "JOIN MY SERVER" button at the bottom
1433
1434
        Parameters
1435
        ----------
1436
        style : Optional[:class:`str`]
1437
            Style of the widget image returned |default| :data:`"shield"`
1438
1439
        Returns
1440
        -------
1441
        :class:`str`
1442
            A PNG image of the guild widget.
1443
        """
1444
        return await self._http.get(f"guilds/{self.id}/widget.png?{style=!s}")
1445
1446
    async def get_welcome_screen(self) -> WelcomeScreen:
1447
        """Returns the welcome screen for the guild.
1448
1449
        Returns
1450
        -------
1451
        :class:`~pincer.objects.guild.welcome_screen.WelcomeScreen`
1452
            The welcome screen for the guild.
1453
        """
1454
        data = await self._http.get(f"guilds/{self.id}/welcome-screen")
1455
        return WelcomeScreen.from_dict(data)
1456
1457
    async def modify_welcome_screen(
1458
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1459
        enabled: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1460
        welcome_channels: Optional[List[WelcomeScreenChannel]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1461
        description: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1462
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1463
    ) -> WelcomeScreen:
1464
        """|coro|
1465
        Modifies the guild's Welcome Screen.
1466
        Requires the ``MANAGE_GUILD`` permission.
1467
1468
        Parameters
1469
        ----------
1470
        enabled : Optional[:class:`bool`]
1471
            Whether the welcome screen is enabled |default| :data:`None`
1472
        welcome_channels : Optional[List[:class:`~pincer.objects.guild.welcome_screen.WelcomeScreenChannel`]]
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (109/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
1473
            Channels linked in the welcome screen and
1474
            their display options |default| :data:`None`
1475
        description : Optional[:class:`str`]
1476
            The server description to show
1477
            in the welcome screen |default| :data:`None`
1478
        reason : Optional[:class:`str`]
1479
            Reason for the modification |default| :data:`None`
1480
1481
        Returns
1482
        -------
1483
        :class:`~pincer.objects.guild.welcome_screen.WelcomeScreen`
1484
            The updated WelcomeScreen object
1485
        """
1486
        data = await self._http.patch(
1487
            f"guilds/{self.id}/welcome-screen",
1488
            data={
1489
                "enabled": enabled,
1490
                "welcome_channels": welcome_channels,
1491
                "description": description,
1492
            },
1493
            headers={"X-Audit-Log-Reason": reason},
1494
        )
1495
        return WelcomeScreen.from_dict(data)
1496
1497
    async def modify_current_user_voice_state(
1498
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1499
        channel_id: Snowflake,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1500
        suppress: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1501
        request_to_speak_timestamp: Optional[Timestamp] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1502
    ):
1503
        """|coro|
1504
        Updates the current user's voice state.
1505
1506
        There are currently several caveats for this endpoint:
1507
        * ``channel_id`` must currently point to a stage channel
1508
        * current user must already have joined ``channel_id``
1509
        * You must have the ``MUTE_MEMBERS`` permission to
1510
          unsuppress yourself. You can always suppress yourself.
1511
        * You must have the ``REQUEST_TO_SPEAK`` permission to request
1512
          to speak. You can always clear your own request to speak.
1513
        * You are able to set ``request_to_speak_timestamp`` to any
1514
          present or future time.
1515
1516
        Parameters
1517
        ----------
1518
        channel_id : :class:`~pincer.utils.snowflake.Snowflake`
1519
            The ID of the channel the user is currently in
1520
        suppress : Optional[:class:`bool`]
1521
            Toggles the user's suppress state |default| :data:`None`
1522
        request_to_speak_timestamp : Optional[:class:`~pincer.utils.timestamp.Timestamp`]
1523
            Sets the user's request to speak
1524
        """
1525
        await self._http.patch(
1526
            f"guilds/{self.id}/voice-states/@me",
1527
            data={
1528
                "channel_id": channel_id,
1529
                "suppress": suppress,
1530
                "request_to_speak_timestamp": request_to_speak_timestamp,
1531
            },
1532
        )
1533
1534
    async def modify_user_voice_state(
1535
        self, user: User, channel_id: Snowflake, suppress: Optional[bool] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1536
    ):
1537
        """|coro|
1538
        Updates another user's voice state.
1539
1540
        There are currently several caveats for this endpoint:
1541
        * ``channel_id`` must currently point to a stage channel
1542
        * User must already have joined ``channel_id``
1543
        * You must have the ``MUTE_MEMBERS`` permission.
1544
          (Since suppression is the only thing that is available currently.)
1545
        * When unsuppressed, non-bot users will have their
1546
          ``request_to_speak_timestamp`` set to the current time.
1547
          Bot users will not.
1548
        * When suppressed, the user will have their
1549
          ``request_to_speak_timestamp`` removed.
1550
1551
        Parameters
1552
        ----------
1553
        user : :class:`~pincer.objects.guild.member.Member`
1554
            The user to update
1555
        channel_id : :class:`~pincer.utils.snowflake.Snowflake`
1556
            The ID of the channel the user is currently in
1557
        suppress : Optional[:class:`bool`]
1558
            Toggles the user's suppress state |default| :data:`None`
1559
        """
1560
        await self._http.patch(
1561
            f"guilds/{self.id}/voice-states/{user.id}",
1562
            data={"channel_id": channel_id, "suppress": suppress},
1563
        )
1564
1565
    async def get_audit_log(self) -> AuditLog:
1566
        """|coro|
1567
        Returns an audit log object for the guild.
1568
        Requires the ``VIEW_AUDIT_LOG`` permission.
1569
1570
        Returns
1571
        -------
1572
        :class:`~pincer.objects.guild.audit_log.AuditLog`
1573
            The audit log object for the guild.
1574
        """
1575
        return AuditLog.from_dict(
1576
            await self._http.get(f"guilds/{self.id}/audit-logs")
1577
        )
1578
1579
    async def get_emojis(self) -> AsyncGenerator[Emoji, None]:
1580
        """|coro|
1581
        Returns an async generator of the emojis in the guild.
1582
1583
        Yields
1584
        ------
1585
        :class:`~pincer.objects.guild.emoji.Emoji`
1586
            The emoji object.
1587
        """
1588
        data = await self._http.get(f"guilds/{self.id}/emojis")
1589
        for emoji_data in data:
1590
            yield Emoji.from_dict(emoji_data)
1591
1592
    async def get_emoji(self, id: Snowflake) -> Emoji:
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in id.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
1593
        """|coro|
1594
        Returns an emoji object for the given ID.
1595
1596
        Parameters
1597
        ----------
1598
        id : :class:`~pincer.utils.snowflake.Snowflake`
1599
            The ID of the emoji
1600
1601
        Returns
1602
        -------
1603
        :class:`~pincer.objects.guild.emoji.Emoji`
1604
            The emoji object.
1605
        """
1606
        return Emoji.from_dict(
1607
            await self._http.get(f"guilds/{self.id}/emojis/{id}")
1608
        )
1609
1610
    async def create_emoji(
1611
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1612
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1613
        name: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1614
        image: File,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1615
        roles: Optional[List[Snowflake]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1616
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1617
    ) -> Emoji:
1618
        """|coro|
1619
        Creates a new emoji for the guild.
1620
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1621
1622
        Emojis and animated emojis have a maximum file size of 256kb.
1623
        Attempting to upload an emoji larger than this limit will fail.
1624
1625
        Parameters
1626
        ----------
1627
        name : :class:`str`
1628
            Name of the emoji
1629
        image : :class:`~pincer.objects.message.file.File`
1630
            The File for the 128x128 emoji image data
1631
        roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake`]]
1632
            Roles allowed to use this emoji |default| :data:`[]`
1633
        reason : Optional[:class:`str`]
1634
            The reason for creating the emoji |default| :data:`None`
1635
1636
        Returns
1637
        -------
1638
        :class:`~pincer.objects.guild.emoji.Emoji`
1639
            The newly created emoji object.
1640
        """
1641
        roles = [] if roles is None else roles
1642
1643
        data = await self._http.post(
1644
            f"guilds/{self.id}/emojis",
1645
            data={"name": name, "image": image.uri, "roles": roles},
1646
            headers={"X-Audit-Log-Reason": reason},
1647
        )
1648
        return Emoji.from_dict(data)
1649
1650
    async def edit_emoji(
1651
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1652
        id: Snowflake,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
Bug Best Practice introduced by
This seems to re-define the built-in id.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
1653
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1654
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1655
        roles: Optional[List[Snowflake]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1656
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1657
    ) -> Emoji:
1658
        """|coro|
1659
        Modifies the given emoji.
1660
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1661
1662
        Parameters
1663
        ----------
1664
        id : :class:`~pincer.utils.snowflake.Snowflake`
1665
            The ID of the emoji
1666
        name : Optional[:class:`str`]
1667
            Name of the emoji |default| :data:`None`
1668
        roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake`]]
1669
            Roles allowed to use this emoji |default| :data:`None`
1670
        reason : Optional[:class:`str`]
1671
            The reason for editing the emoji |default| :data:`None`
1672
1673
        Returns
1674
        -------
1675
        :class:`~pincer.objects.guild.emoji.Emoji`
1676
            The modified emoji object.
1677
        """
1678
        data = await self._http.patch(
1679
            f"guilds/{self.id}/emojis/{id}",
1680
            data={"name": name, "roles": roles},
1681
            headers={"X-Audit-Log-Reason": reason},
1682
        )
1683
        return Emoji.from_dict(data)
1684
1685
    async def delete_emoji(
1686
        self, id: Snowflake, *, reason: Optional[str] = None
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in id.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1687
    ):
1688
        """|coro|
1689
        Deletes the given emoji.
1690
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1691
1692
        Parameters
1693
        ----------
1694
        id : :class:`~pincer.utils.snowflake.Snowflake`
1695
            The ID of the emoji
1696
        reason : Optional[:class:`str`]
1697
            The reason for deleting the emoji |default| :data:`None`
1698
        """
1699
        await self._http.delete(
1700
            f"guilds/{self.id}/emojis/{id}",
1701
            headers={"X-Audit-Log-Reason": reason},
1702
        )
1703
1704
    async def get_templates(self) -> AsyncIterator[GuildTemplate]:
0 ignored issues
show
introduced by
Value 'AsyncIterator' is unsubscriptable
Loading history...
1705
        """|coro|
1706
        Returns an async generator of the guild templates.
1707
1708
        Yields
1709
        -------
1710
        AsyncGenerator[:class:`~pincer.objects.guild.template.GuildTemplate`, :data:`None`]
1711
            The guild template object.
1712
        """
1713
        data = await self._http.get(f"guilds/{self.id}/templates")
1714
        for template_data in data:
1715
            yield GuildTemplate.from_dict(template_data)
1716
1717
    async def create_template(
1718
        self, name: str, description: Optional[str] = None
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1719
    ) -> GuildTemplate:
1720
        """|coro|
1721
        Creates a new template for the guild.
1722
        Requires the ``MANAGE_GUILD`` permission.
1723
1724
        Parameters
1725
        ----------
1726
        name : :class:`str`
1727
            Name of the template (1-100 characters)
1728
        description : Optional[:class:`str`]
1729
            Description of the template
1730
            (0-120 characters) |default| :data:`None`
1731
        Returns
1732
        -------
1733
        :class:`~pincer.objects.guild.template.GuildTemplate`
1734
            The newly created template object.
1735
        """
1736
        data = await self._http.post(
1737
            f"guilds/{self.id}/templates",
1738
            data={"name": name, "description": description},
1739
        )
1740
        return GuildTemplate.from_dict(data)
1741
1742
    async def sync_template(self, template: GuildTemplate) -> GuildTemplate:
1743
        """|coro|
1744
        Syncs the given template.
1745
        Requires the ``MANAGE_GUILD`` permission.
1746
1747
        Parameters
1748
        ----------
1749
        template : :class:`~pincer.objects.guild.template.GuildTemplate`
1750
            The template to sync
1751
1752
        Returns
1753
        -------
1754
        :class:`~pincer.objects.guild.template.GuildTemplate`
1755
            The synced template object.
1756
        """
1757
        data = await self._http.put(
1758
            f"guilds/{self.id}/templates/{template.code}"
1759
        )
1760
        return GuildTemplate.from_dict(data)
1761
1762
    async def edit_template(
1763
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1764
        template: GuildTemplate,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1765
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1766
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1767
        description: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1768
    ) -> GuildTemplate:
1769
        """|coro|
1770
        Modifies the template's metadata.
1771
        Requires the ``MANAGE_GUILD`` permission.
1772
1773
        Parameters
1774
        ----------
1775
        template : :class:`~pincer.objects.guild.template.GuildTemplate`
1776
            The template to edit
1777
        name : Optional[:class:`str`]
1778
            Name of the template (1-100 characters)
1779
            |default| :data:`None`
1780
        description : Optional[:class:`str`]
1781
            Description of the template (0-120 characters)
1782
            |default| :data:`None`
1783
1784
        Returns
1785
        -------
1786
        :class:`~pincer.objects.guild.template.GuildTemplate`
1787
            The edited template object.
1788
        """
1789
        data = await self._http.patch(
1790
            f"guilds/{self.id}/templates/{template.code}",
1791
            data={"name": name, "description": description},
1792
        )
1793
        return GuildTemplate.from_dict(data)
1794
1795
    async def delete_template(self, template: GuildTemplate) -> GuildTemplate:
1796
        """|coro|
1797
        Deletes the given template.
1798
        Requires the ``MANAGE_GUILD`` permission.
1799
1800
        Parameters
1801
        ----------
1802
        template : :class:`~pincer.objects.guild.template.GuildTemplate`
1803
            The template to delete
1804
1805
        Returns
1806
        -------
1807
        :class:`~pincer.objects.guild.template.GuildTemplate`
1808
            The deleted template object.
1809
        """
1810
        data = await self._http.delete(
1811
            f"guilds/{self.id}/templates/{template.code}"
1812
        )
1813
        return GuildTemplate.from_dict(data)
1814
1815
    async def list_stickers(self) -> AsyncIterator[Sticker]:
0 ignored issues
show
introduced by
Value 'AsyncIterator' is unsubscriptable
Loading history...
1816
        """|coro|
1817
        Yields sticker objects for the current guild.
1818
        Includes ``user`` fields if the bot has the
1819
        ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1820
1821
        Yields
1822
        ------
1823
        :class:`~pincer.objects.message.sticker.Sticker`
1824
            a sticker for the current guild
1825
        """
1826
1827
        for sticker in await self._http.get(f"guild/{self.id}/stickers"):
1828
            yield Sticker.from_dict(sticker)
1829
1830
    async def get_sticker(self, _id: Snowflake) -> Sticker:
1831
        """|coro|
1832
        Returns a sticker object for the current guild and sticker IDs.
1833
        Includes the ``user`` field if the bot has the
1834
        ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1835
1836
        Parameters
1837
        ----------
1838
        _id : int
1839
            id of the sticker
1840
1841
        Returns
1842
        -------
1843
        :class:`~pincer.objects.message.sticker.Sticker`
1844
            the sticker requested
1845
        """
1846
        sticker = await self._http.get(f"guilds/{self.id}/stickers/{_id}")
1847
        return Sticker.from_dict(sticker)
1848
1849
    async def create_sticker(
0 ignored issues
show
best-practice introduced by
Too many arguments (6/5)
Loading history...
1850
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1851
        name: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1852
        tags: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1853
        description: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1854
        file: File,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1855
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1856
    ) -> Sticker:
1857
        """|coro|
1858
        Create a new sticker for the guild.
1859
        Requires the ``MANAGE_EMOJIS_AND_STICKERS permission``.
1860
1861
        Parameters
1862
        ----------
1863
        name : str
1864
            name of the sticker (2-30 characters)
1865
        tags : str
1866
            autocomplete/suggestion tags for the sticker (max 200 characters)
1867
        file : :class:`~pincer.objects.message.file.File`
1868
            the sticker file to upload, must be a PNG, APNG, or Lottie JSON file, max 500 KB
1869
        description : str
1870
            description of the sticker (empty or 2-100 characters) |default| :data:`""`
1871
        reason : Optional[:class:`str`] |default| :data:`None`
1872
            reason for creating the sticker
1873
1874
        Returns
1875
        -------
1876
        :class:`~pincer.objects.message.sticker.Sticker`
1877
            the newly created sticker
1878
        """  # noqa: E501
1879
1880
        form = FormData()
1881
        form.add_field("name", name)
1882
        form.add_field("tags", tags)
1883
        form.add_field("description", description)
1884
        form.add_field("file", file.content, content_type=file.content_type)
1885
1886
        payload = form()
1887
1888
        sticker = await self._http.post(
1889
            f"guilds/{self.id}/stickers",
1890
            data=payload,
1891
            headers={"X-Audit-Log-Reason": reason},
1892
            content_type=payload.content_type,
1893
        )
1894
1895
        return Sticker.from_dict(sticker)
1896
1897
    async def delete_sticker(self, _id: Snowflake):
1898
        """|coro|
1899
        Delete the given sticker.
1900
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1901
1902
        Parameters
1903
        ----------
1904
        _id: Snowflake
1905
            id of the sticker
1906
        """
1907
        await self._http.delete(f"guilds/{self.id}/stickers/{_id}")
1908
1909
    async def get_webhooks(self) -> AsyncGenerator[Webhook, None]:
1910
        """|coro|
1911
        Returns an async generator of the guild webhooks.
1912
1913
        Yields
1914
        -------
1915
        AsyncGenerator[:class:`~pincer.objects.guild.webhook.Webhook`, None]
1916
            The guild webhook object.
1917
        """
1918
        data = await self._http.get(f"guilds/{self.id}/webhooks")
1919
        for webhook_data in data:
1920
            yield Webhook.from_dict(webhook_data)
1921
1922
    async def get_scheduled_events(
1923
        self, with_user_count: bool = False
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1924
    ) -> AsyncIterator[ScheduledEvent]:
0 ignored issues
show
introduced by
Value 'AsyncIterator' is unsubscriptable
Loading history...
1925
        """
1926
        Returns an async generator of the guild scheduled events.
1927
1928
        Parameters
1929
        ----------
1930
        with_user_count : :class:`bool`
1931
            Whether to include the user count in the scheduled event.
1932
1933
        Yields
1934
        ------
1935
        :class:`~pincer.objects.guild.scheduled_event.ScheduledEvent`
1936
            The scheduled event object.
1937
        """
1938
        data = await self._http.get(
1939
            f"guilds/{self.id}/scheduled-events",
1940
            param={"with_user_count": with_user_count},
1941
        )
1942
        for event_data in data:
1943
            yield ScheduledEvent.from_dict(event_data)
1944
1945
    async def create_scheduled_event(
0 ignored issues
show
best-practice introduced by
Too many arguments (10/5)
Loading history...
1946
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1947
        name: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1948
        privacy_level: int,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1949
        entity_type: int,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1950
        scheduled_start_time: datetime,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1951
        scheduled_end_time: Optional[datetime] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1952
        entity_metadata: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1953
        channel_id: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1954
        description: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1955
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1956
    ) -> ScheduledEvent:
1957
        """
1958
        Create a new scheduled event for the guild.
1959
1960
        Parameters
1961
        ----------
1962
        name : :class:`str`
1963
            The name of the scheduled event.
1964
        privacy_level : :class:`int`
1965
            The privacy level of the scheduled event.
1966
        entity_type : :class:`int`
1967
            The type of entity to be scheduled.
1968
        scheduled_start_time : :class:`datetime`
1969
            The scheduled start time of the event.
1970
        scheduled_end_time : Optional[:class:`datetime`]
1971
            The scheduled end time of the event.
1972
        entity_metadata : Optional[:class:`str`]
1973
            The metadata of the entity to be scheduled.
1974
        channel_id : Optional[:class:`int`]
1975
            The channel id of the channel to be scheduled.
1976
        description : Optional[:class:`str`]
1977
            The description of the scheduled event.
1978
        reason : Optional[:class:`str`]
1979
            The reason for creating the scheduled event.
1980
            
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1981
        Raises
1982
        ------
1983
        ValueError:
1984
            If an event is created in the past or if an event ends before it starts
1985
1986
        Returns
1987
        -------
1988
        :class:`~pincer.objects.guild.scheduled_event.ScheduledEvent`
1989
            The newly created scheduled event.
1990
        """
1991
        if scheduled_start_time < datetime.now():
1992
            raise ValueError("An event cannot be created in the past")
1993
1994
        if (
1995
            scheduled_end_time
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1996
            and scheduled_end_time < scheduled_start_time
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1997
        ):
1998
            raise ValueError("An event cannot start before it ends")
1999
2000
        data = await self._http.post(
2001
            f"guilds/{self.id}/scheduled-events",
2002
            data={
2003
                "name": name,
2004
                "privacy_level": privacy_level,
2005
                "entity_type": entity_type,
2006
                "scheduled_start_time": scheduled_start_time.isoformat(),
2007
                "scheduled_end_time": scheduled_end_time.isoformat()
2008
                if scheduled_end_time is not None
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (add 22 spaces).
Loading history...
2009
                else None,
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (add 22 spaces).
Loading history...
2010
                "entity_metadata": entity_metadata,
2011
                "channel_id": channel_id,
2012
                "description": description,
2013
            },
2014
            headers={"X-Audit-Log-Reason": reason},
2015
        )
2016
        return ScheduledEvent.from_dict(data)
2017
2018
    async def get_scheduled_event(
2019
        self, _id: int, with_user_count: bool = False
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
2020
    ) -> ScheduledEvent:
2021
        """
2022
        Get a scheduled event by id.
2023
2024
        Parameters
2025
        ----------
2026
        _id : :class:`int`
2027
            The id of the scheduled event.
2028
        with_user_count : :class:`bool`
2029
            Whether to include the user count in the scheduled event.
2030
2031
        Returns
2032
        -------
2033
        :class:`~pincer.objects.guild.scheduled_event.ScheduledEvent`
2034
            The scheduled event object.
2035
        """
2036
        data = await self._http.get(
2037
            f"guilds/{self.id}/scheduled-events/{_id}",
2038
            params={"with_user_count": with_user_count},
2039
        )
2040
        return ScheduledEvent.from_dict(data)
2041
2042
    async def modify_scheduled_event(
0 ignored issues
show
best-practice introduced by
Too many arguments (12/5)
Loading history...
2043
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
2044
        _id: int,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
2045
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
2046
        entity_type: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
2047
        privacy_level: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
2048
        scheduled_start_time: Optional[datetime] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
2049
        scheduled_end_time: Optional[datetime] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
2050
        entity_metadata: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
2051
        channel_id: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
2052
        description: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
2053
        status: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
2054
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
2055
    ) -> ScheduledEvent:
2056
        """
2057
        Modify a scheduled event.
2058
2059
        Parameters
2060
        ----------
2061
        _id : :class:`int`
2062
            The id of the scheduled event.
2063
        name : Optional[:class:`str`]
2064
            The name of the scheduled event.
2065
        entity_type : Optional[:class:`int`]
2066
            The type of entity to be scheduled.
2067
        privacy_level : Optional[:class:`int`]
2068
            The privacy level of the scheduled event.
2069
        scheduled_start_time : Optional[:class:`datetime`]
2070
            The scheduled start time of the event.
2071
        scheduled_end_time : Optional[:class:`datetime`]
2072
            The scheduled end time of the event.
2073
        entity_metadata : Optional[:class:`str`]
2074
            The metadata of the entity to be scheduled.
2075
        channel_id : Optional[:class:`int`]
2076
            The channel id of the channel to be scheduled.
2077
        description : Optional[:class:`str`]
2078
            The description of the scheduled event.
2079
        status : Optional[:class:`int`]
2080
            The status of the scheduled event.
2081
        reason : Optional[:class:`str`]
2082
            The reason for modifying the scheduled event.
2083
2084
        Raises
2085
        ------
2086
        :class:`ValueError`
2087
            If the scheduled event is in the past,
2088
            or if the scheduled end time is before the scheduled start time.
2089
2090
        Returns
2091
        -------
2092
        :class:`~pincer.objects.guild.scheduled_event.ScheduledEvent`
2093
            The scheduled event object.
2094
        """
2095
        if scheduled_start_time:
2096
            if scheduled_start_time < datetime.now():
2097
                raise ValueError("An event cannot be created in the past")
2098
2099
            if (
2100
                scheduled_end_time
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
2101
                and scheduled_end_time < scheduled_start_time
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
2102
            ):
2103
                raise ValueError("An event cannot start before it ends")
2104
2105
        kwargs: Dict[str, str] = remove_none(
2106
            {
2107
                "name": name,
2108
                "privacy_level": privacy_level,
2109
                "entity_type": entity_type,
2110
                "scheduled_start_time": scheduled_start_time.isoformat()
2111
                if scheduled_start_time is not None
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (add 24 spaces).
Loading history...
2112
                else None,
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (add 24 spaces).
Loading history...
2113
                "scheduled_end_time": scheduled_end_time.isoformat()
2114
                if scheduled_end_time is not None
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (add 22 spaces).
Loading history...
2115
                else None,
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (add 22 spaces).
Loading history...
2116
                "entity_metadata": entity_metadata,
2117
                "channel_id": channel_id,
2118
                "description": description,
2119
                "status": status,
2120
            }
2121
        )
2122
2123
        data = await self._http.patch(
2124
            f"guilds/{self.id}/scheduled-events/{_id}",
2125
            data=kwargs,
2126
            headers={"X-Audit-Log-Reason": reason},
2127
        )
2128
        return ScheduledEvent.from_dict(data)
2129
2130
    async def delete_scheduled_event(self, _id: int):
2131
        """
2132
        Delete a scheduled event.
2133
2134
        Parameters
2135
        ----------
2136
        _id : :class:`int`
2137
            The id of the scheduled event.
2138
        """
2139
        await self._http.delete(f"guilds/{self.id}/scheduled-events/{_id}")
2140
2141
    async def get_guild_scheduled_event_users(
2142
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
2143
        _id: int,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
2144
        limit: int = 100,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
2145
        with_member: bool = False,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
2146
        before: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
2147
        after: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
2148
    ) -> AsyncIterator[GuildScheduledEventUser]:
0 ignored issues
show
introduced by
Value 'AsyncIterator' is unsubscriptable
Loading history...
2149
        """
2150
        Get the users of a scheduled event.
2151
2152
        Parameters
2153
        ----------
2154
        _id : :class:`int`
2155
            The id of the scheduled event.
2156
        limit : :class:`int`
2157
            The number of users to retrieve.
2158
        with_member : :class:`bool`
2159
            Whether to include the member object in the scheduled event user.
2160
        before : Optional[:class:`int`]
2161
            consider only users before given user id
2162
        after : Optional[:class:`int`]
2163
            consider only users after given user id
2164
2165
        Yields
2166
        ------
2167
        :class:`~pincer.objects.guild.scheduled_event.GuildScheduledEventUser`
2168
            The scheduled event user object.
2169
        """
2170
        params = remove_none({
2171
            "limit": limit,
2172
            "with_member": with_member,
2173
            "before": before,
2174
            "after": after,
2175
        })
2176
2177
        data = await self._http.get(
2178
            f"guilds/{self.id}/scheduled-events/{_id}/users",
2179
            params=params,
2180
        )
2181
2182
        for user_data in data:
2183
            yield GuildScheduledEventUser.from_dict(user_data)
2184
2185
    @classmethod
2186
    def from_dict(cls, data) -> Guild:
2187
        """
2188
        Parameters
2189
        ----------
2190
        data : :class:`Dict`
2191
            Guild data received from the discord API.
2192
        Returns
2193
        -------
2194
        :class:`~pincer.objects.guild.guild.Guild`
2195
            The new guild object.
2196
        Raises
2197
        ------
2198
        :class:`~pincer.exceptions.UnavailableGuildError`
2199
            The guild is unavailable due to a discord outage.
2200
        """
2201
        if data.get("unavailable", False):
2202
            raise UnavailableGuildError(
2203
                f"Guild \"{data['id']}\" is unavailable due to a discord"
2204
                " outage."
2205
            )
2206
2207
        return super().from_dict(data)
2208
2209
2210
@dataclass(repr=False)
2211
class UnavailableGuild(APIObject):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
2212
    id: Snowflake
2213
    unavailable: bool = True
2214