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

Guild.modify_scheduled_event()   B

Complexity

Conditions 7

Size

Total Lines 39
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 33
dl 0
loc 39
rs 7.688
c 0
b 0
f 0
cc 7
nop 12

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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 (2066/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.file import File
16
from ...exceptions import UnavailableGuildError
17
from ...utils.api_object import APIObject
18
from ...utils.types import MISSING
19
20
if TYPE_CHECKING:
21
    from typing import Any, Dict, List, Optional, Tuple, Union, Generator
22
23
    from collections.abc import AsyncIterator
24
    from .audit_log import AuditLog
25
    from .ban import Ban
26
    from .channel import ChannelType
27
    from .member import GuildMember
28
    from .features import GuildFeature
29
    from .invite import Invite
30
    from .overwrite import Overwrite
31
    from .role import Role
32
    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...
33
    from .stage import StageInstance
34
    from .template import GuildTemplate
35
    from .welcome_screen import WelcomeScreen, WelcomeScreenChannel
36
    from .widget import GuildWidget
37
    from .webhook import Webhook
38
    from ..user.user import User
39
    from ..user.integration import Integration
40
    from ..voice.region import VoiceRegion
41
    from ..events.presence import PresenceUpdateEvent
42
    from ..message.emoji import Emoji
43
    from ..message.sticker import Sticker
44
    from ..user.voice_state import VoiceState
45
    from ...client import Client
46
    from ...utils.timestamp import Timestamp
47
    from ...utils.types import APINullable, JSONSerializable
48
    from ...utils.snowflake import Snowflake
49
50
51
class PremiumTier(IntEnum):
52
    """Represents the boost tier of a guild.
53
    Attributes
54
    ----------
55
    NONE:
56
        Guild has not unlocked any Server Boost perks.
57
    TIER_1:
58
        Guild has unlocked Server Boost level 1 perks.
59
    TIER_2:
60
        Guild has unlocked Server Boost level 2 perks.
61
    TIER_3:
62
        Guild has unlocked Server Boost level 3 perks.
63
    """
64
65
    NONE = 0
66
    TIER_1 = 1
67
    TIER_2 = 2
68
    TIER_3 = 3
69
70
71
class GuildNSFWLevel(IntEnum):
72
    """Represents the NSFW level of a guild.
73
    Attributes
74
    ----------
75
    DEFAULT:
76
        Default NSFW level.
77
    EXPLICIT:
78
        Explicit NSFW level.
79
    SAFE:
80
        SAFE NSFW level.
81
    AGE_RESTRICTED:
82
        Age restricted NSFW level.
83
    """
84
85
    DEFAULT = 0
86
    EXPLICIT = 1
87
    SAFE = 2
88
    AGE_RESTRICTED = 3
89
90
91
class ExplicitContentFilterLevel(IntEnum):
92
    """Represents the filter content level of a guild.
93
    Attributes
94
    ----------
95
    DISABLED:
96
        Media content will not be scanned.
97
    MEMBERS_WITHOUT_ROLES:
98
        Media content sent by members without roles will be scanned.
99
    ALL_MEMBERS:
100
        Media content sent by all members will be scanned.
101
    """
102
103
    DISABLED = 0
104
    MEMBERS_WITHOUT_ROLES = 1
105
    ALL_MEMBERS = 2
106
107
108
class MFALevel(IntEnum):
109
    """Represents the multi-factor authentication level of a guild.
110
    Attributes
111
    ----------
112
    NONE:
113
        Guild has no MFA/2FA requirement for moderation actions.
114
    ELEVATED:
115
        Guild has a 2FA requirement for moderation actions
116
    """
117
118
    NONE = 0
119
    ELEVATED = 1
120
121
122
class VerificationLevel(IntEnum):
123
    """Represents the verification level of a guild.
124
    Attributes
125
    ----------
126
    NONE:
127
        Unrestricted.
128
    LOW:
129
        Must have verified email on account.
130
    MEDIUM:
131
        Must be registered on Discord for longer than 5 minutes.
132
    HIGH:
133
        Must be a member of the server for longer than 10 minutes.
134
    VERY_HIGH:
135
        Must have a verified phone number.
136
    """
137
138
    NONE = 0
139
    LOW = 1
140
    MEDIUM = 2
141
    HIGH = 3
142
    VERY_HIGH = 4
143
144
145
class DefaultMessageNotificationLevel(IntEnum):
146
    """Represents the default message notification level of a guild.
147
    Attributes
148
    ----------
149
    ALL_MESSAGES:
150
        Members will receive notifications for all messages by default.
151
    ONLY_MENTIONS:
152
        Members will receive notifications only for messages that @mention them by default.
153
    """
154
155
    # noqa: E501
156
    ALL_MESSAGES = 0
157
    ONLY_MENTIONS = 1
158
159
160
class SystemChannelFlags(IntEnum):
161
    """Represents the system channel flags of a guild.
162
    Attributes
163
    ----------
164
    SUPPRESS_JOIN_NOTIFICATIONS:
165
        Suppress member join notifications.
166
    SUPPRESS_PREMIUM_SUBSCRIPTIONS:
167
        Suppress server boost notifications.
168
    SUPPRESS_GUILD_REMINDER_NOTIFICATIONS:
169
        Suppress server setup tips.
170
    SUPPRESS_JOIN_NOTIFICATION_REPLIES:
171
        Hide member join sticker reply buttons
172
    """
173
174
    SUPPRESS_JOIN_NOTIFICATIONS = 1 << 0
175
    SUPPRESS_PREMIUM_SUBSCRIPTIONS = 1 << 1
176
    SUPPRESS_GUILD_REMINDER_NOTIFICATIONS = 1 << 2
177
    SUPPRESS_JOIN_NOTIFICATION_REPLIES = 1 << 3
178
179
180
@dataclass(repr=False)
181
class GuildPreview(APIObject):
0 ignored issues
show
best-practice introduced by
Too many instance attributes (10/7)
Loading history...
182
    """Represents a guild preview.
183
    Attributes
184
    ----------
185
    id: :class:`Snowflake`
186
        The guild ID.
187
    name: :class:`str`
188
        The guild name.
189
    icon: :class:`str`
190
        The guild icon hash.
191
    splash: :class:`str`
192
        The guild splash hash.
193
    discovery_splash: :class:`str`
194
        The guild discovery splash hash.
195
    emojis: :class:`List[Emoji]`
196
        The guild emojis.
197
    features: :class:`List[GuildFeature]`
198
        The guild features.
199
    approximate_member_count: :class:`int`
200
        The approximate member count.
201
    approximate_presence_count: :class:`int`
202
        The approximate number of online members in this guild
203
    description: :class:`str`
204
        The guild description.
205
    """
206
207
    id: Snowflake
208
    name: str
209
    emojis: List[Emoji]
210
    features: List[GuildFeature]
211
    approximate_member_count: int
212
    approximate_presence_count: int
213
214
    icon: APINullable[str] = MISSING
215
    splash: APINullable[str] = MISSING
216
    discovery_splash: APINullable[str] = MISSING
217
    description: APINullable[str] = MISSING
218
219
220
@dataclass(repr=False)
221
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...
222
    """Represents a Discord guild/server in which your client resides.
223
    Attributes
224
    ----------
225
    afk_channel_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
226
        Id of afk channel
227
    afk_timeout: :class:`int`
228
        Afk timeout in seconds
229
    application_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
230
        Application id of the guild creator if it is bot-created
231
    banner: Optional[:class:`str`]
232
        Banner hash
233
    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...
234
        Default message notifications level
235
    description: Optional[:class:`str`]
236
        The description of a Community guild
237
    discovery_splash: Optional[:class:`str`]
238
        Discovery splash hash;
239
        only present for guilds with the "DISCOVERABLE" feature
240
    emojis: List[:class:`~pincer.objects.message.emoji.Emoji`]
241
        Custom guild emojis
242
    explicit_content_filter: :class:`~pincer.objects.guild.guild.ExplicitContentFilterLevel`
243
        Explicit content filter level
244
    features: List[:class:`~pincer.objects.guild.features.GuildFeature`]
245
        Enabled guild features
246
    id: :class:`~pincer.utils.snowflake.Snowflake`
247
        Guild id
248
    icon: Optional[:class:`str`]
249
        Icon hash
250
    mfa_level: :class:`~pincer.objects.guild.guild.MFALevel`
251
        Required MFA level for the guild
252
    name: :class:`str`
253
        Guild name (2-100 characters, excluding trailing and leading
254
        whitespace)
255
    nsfw_level: :class:`~pincer.objects.guild.guild.NSFWLevel`
256
        Guild NSFW level
257
    owner_id: :class:`~pincer.utils.snowflake.Snowflake`
258
        Id of owner
259
    preferred_locale: :class:`str`
260
        The preferred locale of a Community guild;
261
        used in server discovery and notices from Discord;
262
        defaults to "en-US"
263
    premium_tier: :class:`~pincer.objects.guild.guild.PremiumTier`
264
        Premium tier (Server Boost level)
265
    public_updates_channel_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
266
        The id of the channel where admins
267
        and moderators of Community guilds receive notices from Discord
268
    roles: List[:class:`~pincer.objects.guild.role.Role`]
269
        Roles in the guild
270
    rules_channel_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
271
        The id of the channel where Community guilds can display rules
272
        and/or guidelines
273
    splash: Optional[:class:`str`]
274
        Splash hash
275
    system_channel_flags: :class:`~pincer.objects.guild.guild.SystemChannelFlags`
276
        System channel flags
277
    system_channel_id: Optional[:class:`~pincer.utils.snowflake.Snowflake`]
278
        The id of the channel where guild notices
279
        such as welcome messages and boost events are posted
280
    vanity_url_code: Optional[:class:`str`]
281
        The vanity url code for the guild
282
    verification_level: :class:`~pincer.objects.guild.guild.VerificationLevel`
283
        Verification level required for the guild
284
    approximate_member_count: APINullable[:class:`int`]
285
        Approximate number of members in this guild, returned from the
286
        `GET /guilds/<id>` endpoint when with_counts is true
287
    approximate_presence_count: APINullable[:class:`int`]
288
        Approximate number of non-offline members in this guild,
289
        returned from the `GET /guilds/<id>`
290
        endpoint when with_counts is true
291
    channels: APINullable[List[:class:`~pincer.objects.guild.channel.Channel`]]
292
        Channels in the guild
293
    icon_hash: APINullable[Optional[:class:`str`]]
294
        Icon hash, returned when in the template object
295
    joined_at: APINullable[:class:`~pincer.utils.timestamp.Timestamp`]
296
        When this guild was joined at
297
    large: APINullable[:class:`bool`]
298
        True if this is considered a large guild
299
    max_members: APINullable[:class:`int`]
300
        The maximum number of members for the guild
301
    max_presences: APINullable[Optional[:class:`int`]]
302
        The maximum number of presences for the guild
303
        (null is always returned, apart from the largest of guilds)
304
    max_video_channel_users: APINullable[:class:`int`]
305
        The maximum amount of users in a video channel
306
    members: APINullable[List[:class:`~pincer.objects.guild.member.GuildMember`]]
307
        Users in the guild
308
    member_count: APINullable[:class:`bool`]
309
        Total number of members in this guild
310
    nsfw: APINullable[:class:`bool`]
311
        Boolean if the server is NSFW
312
    owner: APINullable[:class:`bool`]
313
        True if the user is the owner of the guild
314
    permissions: APINullable[:class:`str`]
315
        Total permissions for the user in the guild
316
        (excludes overwrites)
317
    premium_subscription_count: APINullable[:class:`int`]
318
        The number of boosts this guild currently has
319
    presences: APINullable[List[:class:`~pincer.objects.events.presence.PresenceUpdateEvent`]]
320
        Presences of the members in the guild,
321
        will only include non-offline members if the size is greater
322
        than large threshold
323
    stage_instances: APINullable[List[:class:`~pincer.objects.guild.stage.StageInstance`]]
324
        Stage instances in the guild
325
    stickers: Optional[List[:class:`~pincer.objects.message.sticker.Sticker`]]
326
        Custom guild stickers
327
    region: APINullable[Optional[:class:`str`]]
328
        Voice region id for the guild (deprecated)
329
    threads: APINullable[List[:class:`~pincer.objects.guild.channel.Channel`]]
330
        All active threads in the guild that current user
331
        has permission to view
332
    unavailable: APINullable[:class:`bool`]
333
        True if this guild is unavailable due to an outage
334
    voice_states: APINullable[List[:class:`~pincer.objects.user.voice_state.VoiceState`]]
335
        States of members currently in voice channels;
336
        lacks the guild_id key
337
    widget_enabled: APINullable[:class:`bool`]
338
        True if the server widget is enabled
339
    widget_channel_id: APINullable[Optional[:class:`~pincer.utils.snowflake.Snowflake`]]
340
        The channel id that the widget will generate an invite to,
341
        or null if set to no invite
342
    welcome_screen: APINullable[:class:`~pincer.objects.guild.welcome_screen.WelcomeScreen`]
343
        The welcome screen of a Community guild, shown to new members,
344
        returned in an Invite's guild object
345
    """
346
347
    # noqa: E501
348
    features: List[GuildFeature]
349
    id: Snowflake
350
    name: str
351
    nsfw_level: GuildNSFWLevel
352
    verification_level: VerificationLevel
353
354
    # Guild invites missing
355
    system_channel_flags: APINullable[SystemChannelFlags] = MISSING
356
    explicit_content_filter: APINullable[ExplicitContentFilterLevel] = MISSING
357
    premium_tier: APINullable[PremiumTier] = MISSING
358
    default_message_notifications: APINullable[
359
        DefaultMessageNotificationLevel
360
    ] = MISSING
361
    mfa_level: APINullable[MFALevel] = MISSING
362
    owner_id: APINullable[Snowflake] = MISSING
363
    afk_timeout: APINullable[int] = MISSING
364
    emojis: APINullable[List[Emoji]] = MISSING
365
    preferred_locale: APINullable[str] = MISSING
366
    roles: APINullable[List[Role]] = MISSING
367
368
    guild_scheduled_events: APINullable[List[ScheduledEvent]] = MISSING
369
    lazy: APINullable[bool] = MISSING
370
    premium_progress_bar_enabled: APINullable[bool] = MISSING
371
    guild_hashes: APINullable[Dict] = MISSING
372
    afk_channel_id: APINullable[Snowflake] = MISSING
373
    application_id: APINullable[Snowflake] = MISSING
374
    embedded_activities: APINullable[List] = MISSING
375
    banner: APINullable[str] = MISSING
376
    description: APINullable[str] = MISSING
377
    discovery_splash: APINullable[str] = MISSING
378
    icon: APINullable[str] = MISSING
379
    public_updates_channel_id: APINullable[Snowflake] = MISSING
380
    rules_channel_id: APINullable[Snowflake] = MISSING
381
    splash: APINullable[str] = MISSING
382
    system_channel_id: APINullable[Snowflake] = MISSING
383
    vanity_url_code: APINullable[str] = MISSING
384
385
    application_command_counts: APINullable[Dict] = MISSING
386
    application_command_count: APINullable[int] = MISSING
387
    approximate_member_count: APINullable[int] = MISSING
388
    approximate_presence_count: APINullable[int] = MISSING
389
    channels: APINullable[List[Channel]] = field(default_factory=list)
390
    # 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...
391
    hub_type: APINullable[Any] = MISSING
392
    icon_hash: APINullable[Optional[str]] = MISSING
393
    joined_at: APINullable[Timestamp] = MISSING
394
    large: APINullable[bool] = MISSING
395
    max_members: APINullable[int] = MISSING
396
    max_presences: APINullable[Optional[int]] = MISSING
397
    max_video_channel_users: APINullable[int] = MISSING
398
    members: APINullable[List[GuildMember]] = MISSING
399
    member_count: APINullable[bool] = MISSING
400
    nsfw: APINullable[bool] = MISSING
401
    # Note: This is missing from discord's docs but in the api
402
    owner: APINullable[bool] = MISSING
403
    permissions: APINullable[str] = MISSING
404
    premium_subscription_count: APINullable[int] = MISSING
405
    presences: APINullable[List[PresenceUpdateEvent]] = MISSING
406
    stage_instances: APINullable[List[StageInstance]] = MISSING
407
    stickers: APINullable[List[Sticker]] = MISSING
408
    region: APINullable[Optional[str]] = MISSING
409
    threads: APINullable[List[Channel]] = MISSING
410
    # Guilds are considered available unless otherwise specified
411
    unavailable: APINullable[bool] = False
412
    voice_states: APINullable[List[VoiceState]] = MISSING
413
    widget_enabled: APINullable[bool] = MISSING
414
    widget_channel_id: APINullable[Optional[Snowflake]] = MISSING
415
    welcome_screen: APINullable[WelcomeScreen] = MISSING
416
417
    @classmethod
418
    async def from_id(
419
        cls,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
420
        client: Client,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
421
        _id: Union[int, Snowflake],
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
422
        with_counts: bool = False,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
423
    ) -> Guild:
424
        """
425
        Parameters
426
        ----------
427
        client : :class:`~pincer.Client`
428
            Client object to use the http gateway from.
429
        _id : :class:`~pincer.utils.snowflake.Snowflake`
430
            Guild ID.
431
        Returns
432
        -------
433
        :class:`~pincer.objects.guild.guild.Guild`
434
            The new guild object.
435
        """
436
        data = await client.http.get(
437
            f"/guilds/{_id}",
438
            # Yarl don't support boolean params
439
            params={"with_counts": "true" if with_counts else None},
440
        )
441
        channel_data = await client.http.get(f"/guilds/{_id}/channels")
442
443
        data["channels"]: List[Channel] = [
444
            Channel.from_dict(i) for i in (channel_data or [])
445
        ]
446
447
        return Guild.from_dict(data)
448
449
    async def get_member(self, _id: int) -> GuildMember:
450
        """|coro|
451
        Fetches a GuildMember from its identifier
452
453
        Parameters
454
        ----------
455
        _id: int
456
            The id of the guild member which should be fetched from the Discord
457
            gateway.
458
        Returns
459
        -------
460
        :class:`~pincer.objects.guild.member.GuildMember`
461
            A GuildMember object.
462
        """
463
        return await GuildMember.from_id(self._client, self.id, _id)
464
465
    @overload
466
    async def modify_member(
467
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
468
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
469
        _id: int,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
470
        nick: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
471
        roles: Optional[List[Snowflake]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
472
        mute: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
473
        deaf: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
474
        channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
475
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
476
        communication_disabled_until: Optional[Timestamp] = MISSING,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
477
    ) -> GuildMember:
478
        """|coro|
479
        Modifies a member in the guild from its identifier and based on the
480
        keyword arguments provided.
481
        Parameters
482
        ----------
483
        _id : int
484
            Id of the member to modify
485
        nick : Optional[:class:`str`]
486
            New nickname for the member |default| :data:`None`
487
        roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake]]
488
            New roles for the member |default| :data:`None`
489
        mute : Optional[:class:`bool`]
490
            Whether the member is muted |default| :data:`None`
491
        deaf : Optional[:class:`bool`]
492
            Whether the member is deafened |default| :data:`None`
493
        channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake]
494
            Voice channel id to move to |default| :data:`None`
495
        reason : Optional[:class:`str`]
496
            audit log reason |default| :data:`None`
497
        communication_disabled_until : Optional[Timestamp]
498
            When the member can communicate again, requires ``MODERATE_MEMBERS``
499
            permissions. Set to ``None`` to disable the timeout.
500
501
        Returns
502
        -------
503
        :class:`~pincer.objects.guild.member.GuildMember`
504
            The new member object.
505
        """
506
        ...
507
508
    async def modify_member(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
509
        self, _id: int, reason=None, **kwargs
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
510
    ) -> GuildMember:
511
        if kwargs.get("communication_disabled_until") is MISSING:
512
            kwargs.pop("communication_disabled_until")
513
        data = await self._http.patch(
514
            f"guilds/{self.id}/members/{_id}",
515
            data=kwargs,
516
            headers={"X-Audit-Log-Reason": reason},
517
        )
518
        return GuildMember.from_dict(data)
519
520
    @overload
521
    async def create_channel(
522
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
523
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
524
        name: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
525
        type: Optional[ChannelType] = None,
0 ignored issues
show
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...
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
526
        topic: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
527
        bitrate: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
528
        user_limit: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
529
        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...
530
        position: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
531
        permission_overwrites: Optional[List[Overwrite]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
532
        parent_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
533
        nsfw: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
534
    ) -> Channel:
535
        """|coro|
536
        Create a new channel object for the guild.
537
538
        Parameters
539
        ----------
540
        name : str
541
            channel name (1-100 characters)
542
        type : Optional[:class:int`]
543
            the type of channel
544
        topic : Optional[:class:str`]
545
            channel topic (0-1024 characters)
546
        bitrate : Optional[:class:`int`]
547
            the bitrate (in bits) of the voice channel (voice only)
548
        user_limit : Optional[:class:`int`]
549
            the user limit of the voice channel (voice only)
550
        rate_limit_per_user : Optional[:class:`int`]
551
            amount of seconds a user has to wait
552
            before sending another message (0-21600)
553
            bots, as well as users with the permission
554
            manage_messages or manage_channel, are unaffected
555
        position : Optional[:class:`int`]
556
            sorting position of the channel
557
        permission_overwrites : Optional[List[:class:`~pincer.objects.guild.overwrite.Overwrite`]]
558
            the channel's permission overwrites
559
        parent_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
560
            id of the parent category for a channel
561
        nsfw : Optional[:class:`bool`]
562
            whether the channel is nsfw
563
        reason : Optional[:class:`str`]
564
            audit log reason |default| :data:`None`
565
        Returns
566
        -------
567
        :class:`~pincer.objects.guild.channel.Channel`
568
            The new channel object.
569
        """
570
        ...
571
572
    async def create_channel(self, *, reason: Optional[str] = None, **kwargs):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
573
        data = await self._http.post(
574
            f"guilds/{self.id}/channels",
575
            data=kwargs,
576
            headers={"X-Audit-Log-Reason": reason},
577
        )
578
        return Channel.from_dict(data)
579
580
    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...
581
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
582
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
583
        *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...
584
    ):
585
        """|coro|
586
        Create a new channel object for the guild.
587
588
        Parameters
589
        ----------
590
        reason : Optional[:class:`str`]
591
            audit log reason |default| :data:`None`
592
        \\*channel : Dict[str, Optional[Union[int, bool, :class:`~pincer.utils.snowflake.Snowflake`]
593
            Keys:
594
                - id : :class:`~pincer.utils.snowflake.Snowflake`
595
                - position : Optional[:class:`int`]
596
                - lock_permissions : Optional[:class:`bool`]
597
                - parent_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
598
        """
599
        await self._http.patch(
600
            f"guilds/{self.id}/channels",
601
            data=channel,
602
            headers={"X-Audit-Log-Reason": reason},
603
        )
604
605
    async def list_active_threads(
606
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
607
    ) -> Tuple[Generator[Thread], Generator[GuildMember]]:
608
        """|coro|
609
        Returns all active threads in the guild,
610
        including public and private threads.
611
612
        Returns
613
        -------
614
        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...
615
            The new member object.
616
        """
617
        data = await self._http.get(f"guilds/{self.id}/threads/active")
618
619
        threads = (Channel.from_dict(channel) for channel in data["threads"])
620
        members = (GuildMember.from_dict(member) for member in data["members"])
621
622
        return threads, members
623
624
    async def list_guild_members(
625
        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...
626
    ) -> AsyncIterator[GuildMember]:
0 ignored issues
show
introduced by
Value 'AsyncIterator' is unsubscriptable
Loading history...
627
        """|coro|
628
        Returns a list of guild member objects that are members of the guild.
629
630
        Parameters
631
        ----------
632
        limit : int
633
            max number of members to return (1-1000) |default| :data:`1`
634
        after : int
635
            the highest user id in the previous page |default| :data:`0`
636
637
        Yields
638
        ------
639
        :class:`~pincer.objects.guild.member.GuildMember`
640
            the guild member object that is in the guild
641
        """
642
643
        members = await self._http.get(
644
            f"guilds/{self.id}/members", params={"limit": limit, "after": after}
645
        )
646
647
        for member in members:
648
            yield GuildMember.from_dict(member)
649
650
    async def search_guild_members(
651
        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...
652
    ) -> AsyncIterator[GuildMember]:
0 ignored issues
show
introduced by
Value 'AsyncIterator' is unsubscriptable
Loading history...
653
        """|coro|
654
        Returns a list of guild member objects whose
655
        username or nickname starts with a provided string.
656
657
        Parameters
658
        ----------
659
        query : str
660
            Query string to match username(s) and nickname(s) against.
661
        limit : Optional[int]
662
            max number of members to return (1-1000) |default| :data:`1`
663
664
        Yields
665
        -------
666
        :class:`~pincer.objects.guild.member.GuildMember`
667
            guild member objects
668
        """
669
670
        data = await self._http.get(
671
            f"guilds/{self.id}/members/search",
672
            params={"query": query, "limit": limit},
673
        )
674
675
        for member in data:
676
            yield GuildMember.from_dict(member)
677
678
    @overload
679
    async def add_guild_member(
680
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
681
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
682
        user_id: Snowflake,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
683
        access_token: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
684
        nick: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
685
        roles: Optional[List[Snowflake]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
686
        mute: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
687
        deaf: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
688
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
689
    ) -> Optional[GuildMember]:
690
        """|coro|
691
        Adds a user to the guild, provided you have a
692
        valid oauth2 access token for the user with the guilds.join scope.
693
694
        Parameters
695
        ----------
696
        user_id : str
697
            id of the user to be added
698
        access_token : str
699
            an oauth2 access token granted with the guilds.join to
700
            the bot's application for the user you want to add to the guild
701
        nick : Optional[str]
702
            value to set users nickname to
703
        roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake`]]
704
            array of role ids the member is assigned
705
        mute : Optional[bool]
706
            whether the user is muted in voice channels
707
        deaf : Optional[bool]
708
            whether the user is deafened in voice channels
709
        reason : Optional[:class:`str`]
710
            audit log reason |default| :data:`None`
711
        Returns
712
        -------
713
        :class:`~pincer.objects.guild.member.GuildMember`
714
            If the user is not in the guild
715
        None
716
            If the user is in the guild
717
        """
718
719
    async def add_guild_member(self, user_id, reason=None, **kwargs):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
720
        data = await self._http.put(
721
            f"guilds/{self.id}/members/{user_id}",
722
            data=kwargs,
723
            headers={"X-Audit-Log-Reason": reason},
724
        )
725
726
        return GuildMember.from_dict(data) if data else None
727
728
    async def modify_current_member(
729
        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...
730
    ) -> GuildMember:
731
        """|coro|
732
        Modifies the current member in a guild.
733
734
        Parameters
735
        ----------
736
        nick : str
737
            value to set users nickname to
738
        reason : Optional[:class:`str`]
739
            audit log reason |default| :data:`None`
740
        Returns
741
        -------
742
        class:`~pincer.objects.guild.member.GuildMember
743
            current guild member
744
        """
745
        data = self._http.patch(
746
            f"guilds/{self.id}/members/@me",
747
            {"nick": nick},
748
            headers={"X-Audit-Log-Reason": reason},
749
        )
750
        return GuildMember.from_dict(data)
751
752
    async def add_guild_member_role(
753
        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...
754
    ) -> None:
755
        """|coro|
756
        Adds a role to a guild member.
757
758
        Parameters
759
        ----------
760
        user_id : int
761
            id of the user to give a role to
762
        role_id : int
763
            id of a role
764
        reason : Optional[:class:`str`]
765
            audit log reason |default| :data:`None`
766
        """
767
        data = await self._http.put(
0 ignored issues
show
Unused Code introduced by
The variable data seems to be unused.
Loading history...
768
            f"guilds/{self.id}/{user_id}/roles/{role_id}",
769
            headers={"X-Audit-Log-Reason": reason},
770
        )
771
772
    async def remove_guild_member_role(
773
        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...
774
    ):
775
        """|coro|
776
        Removes a role from a guild member.
777
778
        Parameters
779
        ----------
780
        user_id : int
781
            id of the user to remove a role from
782
        role_id : int
783
            id of a role
784
        reason : Optional[:class:`str`]
785
            audit log reason |default| :data:`None`
786
        """
787
        await self._http.delete(
788
            f"guilds/{self.id}/{user_id}/roles/{role_id}",
789
            headers={"X-Audit-Log-Reason": reason},
790
        )
791
792
    async def remove_guild_member(
793
        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...
794
    ):
795
        """|coro|
796
        Remove a member from a guild.
797
798
        Parameters
799
        ----------
800
        user_id : int
801
            id of the user to remove from the guild
802
        reason : Optional[:class:`str`]
803
            audit log reason |default| :data:`None`
804
        """
805
        await self._http.delete(
806
            f"guilds/{self.id}/members/{user_id}",
807
            headers={"X-Audit-Log-Reason": reason},
808
        )
809
810
    async def ban(
811
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
812
        member_id: int,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
813
        reason: str = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
814
        delete_message_days: int = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
815
    ):
816
        """
817
        Parameters
818
        ----------
819
        member_id : :class:`int`
820
            ID of the guild member to ban.
821
        reason : Optional[:class:`str`]
822
            Reason for the kick.
823
        delete_message_days : Optional[:class:`int`]
824
            Number of days to delete messages for (0-7)
825
        """
826
        headers = {}
827
828
        if reason is not None:
829
            headers["X-Audit-Log-Reason"] = reason
830
831
        data = {}
832
833
        if delete_message_days is not None:
834
            data["delete_message_days"] = delete_message_days
835
836
        await self._http.put(
837
            f"/guilds/{self.id}/bans/{member_id}", data=data, headers=headers
838
        )
839
840
    async def kick(self, member_id: int, reason: Optional[str] = None):
841
        """|coro|
842
        Kicks a guild member.
843
        Parameters
844
        ----------
845
        member_id : :class:`int`
846
            ID of the guild member to kick.
847
        reason : Optional[:class:`str`]
848
            Reason for the kick.
849
        """
850
851
        headers = {}
852
853
        if reason is not None:
854
            headers["X-Audit-Log-Reason"] = reason
855
856
        await self._http.delete(
857
            f"/guilds/{self.id}/members/{member_id}", headers=headers
858
        )
859
860
    async def get_roles(self) -> AsyncGenerator[Role, None]:
861
        """|coro|
862
        Fetches all the roles in the guild.
863
864
        Yields
865
        -------
866
        AsyncGenerator[:class:`~pincer.objects.guild.role.Role`, :data:`None`]
867
            An async generator of Role objects.
868
        """
869
        data = await self._http.get(f"guilds/{self.id}/roles")
870
        for role_data in data:
871
            yield Role.from_dict(role_data)
872
873
    @overload
874
    async def create_role(
875
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
876
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
877
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
878
        name: Optional[str] = "new role",
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
879
        permissions: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
880
        color: Optional[int] = 0,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
881
        hoist: Optional[bool] = False,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
882
        icon: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
883
        unicode_emoji: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
884
        mentionable: Optional[bool] = False,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
885
    ) -> Role:
886
        """|coro|
887
        Creates a new role for the guild.
888
        Requires the ``MANAGE_ROLES`` permission.
889
890
        Parameters
891
        ----------
892
        reason : Optional[:class:`str`]
893
            Reason for creating the role. |default| :data:`None`
894
        name : Optional[:class:`str`]
895
            name of the role |default| :data:`"new role"`
896
        permissions : Optional[:class:`str`]
897
            bitwise value of the enabled/disabled
898
            permissions, set to @everyone permissions
899
            by default |default| :data:`None`
900
        color : Optional[:class:`int`]
901
            RGB color value |default| :data:`0`
902
        hoist : Optional[:class:`bool`]
903
            whether the role should be displayed
904
            separately in the sidebar |default| :data:`False`
905
        icon : Optional[:class:`str`]
906
            the role's icon image (if the guild has
907
            the ``ROLE_ICONS`` feature) |default| :data:`None`
908
        unicode_emoji : Optional[:class:`str`]
909
            the role's unicode emoji as a standard emoji (if the guild
910
            has the ``ROLE_ICONS`` feature) |default| :data:`None`
911
        mentionable : Optional[:class:`bool`]
912
            whether the role should be mentionable |default| :data:`False`
913
914
        Returns
915
        -------
916
        :class:`~pincer.objects.guild.role.Role`
917
            The new role object.
918
        """
919
        ...
920
921
    async def create_role(self, reason: Optional[str] = None, **kwargs) -> Role:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
922
        return Role.from_dict(
923
            await self._http.post(
924
                f"guilds/{self.id}/roles",
925
                data=kwargs,
926
                headers={"X-Audit-Log-Reason": reason},
927
            )
928
        )
929
930
    async def edit_role_position(
931
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
932
        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...
933
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
934
        position: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
935
    ) -> AsyncGenerator[Role, None]:
936
        """|coro|
937
        Edits the position of a role.
938
939
        Parameters
940
        ----------
941
        id : :class:`~pincer.utils.snowflake.Snowflake`
942
            The role ID
943
        reason : Optional[:class:`str`]
944
            Reason for editing the role position. |default| :data:`None`
945
        position : Optional[:class:`int`]
946
            Sorting position of the role |default| :data:`None`
947
948
        Yields
949
        -------
950
        AsyncGenerator[:class:`~pincer.objects.guild.role.Role`, :data:`None`]
951
            An async generator of all the guild's role objects.
952
        """
953
        data = await self._http.patch(
954
            f"guilds/{self.id}/roles",
955
            data={"id": id, "position": position},
956
            headers={"X-Audit-Log-Reason": reason},
957
        )
958
        for role_data in data:
959
            yield Role.from_dict(role_data)
960
961
    @overload
962
    async def edit_role(
963
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
964
        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...
965
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
966
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
967
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
968
        permissions: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
969
        color: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
970
        hoist: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
971
        icon: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
972
        unicode_emoji: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
973
        mentionable: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
974
    ) -> Role:
975
        """|coro|
976
        Edits a role.
977
        Requires the ``MANAGE_ROLES`` permission.
978
979
        Parameters
980
        ----------
981
        id : :class:`~pincer.utils.snowflake.Snowflake`
982
            The role ID
983
        reason : Optional[:class:`str`]
984
            Reason for editing the role |default| :data:`None`
985
        name : Optional[:class:`str`]
986
            Name of the role |default| :data:`None`
987
        permissions : Optional[:class:`str`]
988
            Bitwise value of the enabled/disabled
989
            permissions |default| :data:`None`
990
        color : Optional[:class:`int`]
991
            RGB color value |default| :data:`None`
992
        hoist : Optional[:class:`bool`]
993
            Whether the role should be displayed
994
            separately in the sidebar |default| :data:`None`
995
        icon : Optional[:class:`str`]
996
            The role's icon image (if the guild has
997
            the ``ROLE_ICONS`` feature) |default| :data:`None`
998
        unicode_emoji : Optional[:class:`str`]
999
            The role's unicode emoji as a standard emoji (if the guild
1000
            has the ``ROLE_ICONS`` feature) |default| :data:`None`
1001
        mentionable : Optional[:class:`bool`]
1002
            Whether the role should be mentionable |default| :data:`None`
1003
1004
        Returns
1005
        -------
1006
        :class:`~pincer.objects.guild.role.Role`
1007
            The edited role object.
1008
        """
1009
        ...
1010
1011
    async def edit_role(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
1012
        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...
1013
    ) -> Role:
1014
        return Role.from_dict(
1015
            await self._http.patch(
1016
                f"guilds/{self.id}/roles/{id}",
1017
                data=kwargs,
1018
                headers={"X-Audit-Log-Reason": reason},
1019
            )
1020
        )
1021
1022
    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...
1023
        """|coro|
1024
        Deletes a role.
1025
        Requires the `MANAGE_ROLES` permission.
1026
1027
        Parameters
1028
        ----------
1029
        id : :class:`~pincer.utils.snowflake.Snowflake`
1030
            The role ID
1031
        reason : Optional[:class:`str`]
1032
            The reason for deleting the role |default| :data:`None`
1033
        """
1034
        await self._http.delete(
1035
            f"guilds/{self.id}/roles/{id}",
1036
            headers={"X-Audit-Log-Reason": reason},
1037
        )
1038
1039
    async def get_bans(self) -> AsyncGenerator[Ban, None]:
1040
        """|coro|
1041
        Fetches all the bans in the guild.
1042
1043
        Yields
1044
        -------
1045
        AsyncGenerator[:class:`~pincer.objects.guild.ban.Ban`, :data:`None`]
1046
            An async generator of Ban objects.
1047
        """
1048
        data = await self._http.get(f"guilds/{self.id}/bans")
1049
        for ban_data in data:
1050
            yield Ban.from_dict(ban_data)
1051
1052
    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...
1053
        """|coro|
1054
        Fetches a ban from the guild.
1055
1056
        Parameters
1057
        ----------
1058
        id : :class:`~pincer.utils.snowflake.Snowflake`
1059
            The user ID
1060
1061
        Returns
1062
        -------
1063
        :class:`~pincer.objects.guild.ban.Ban`
1064
            The Ban object.
1065
        """
1066
        return Ban.from_dict(
1067
            await self._http.get(f"guilds/{self.id}/bans/{id}")
1068
        )
1069
1070
    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...
1071
        """|coro|
1072
        Unbans a user from the guild.
1073
1074
        Parameters
1075
        ----------
1076
        id : :class:`~pincer.utils.snowflake.Snowflake`
1077
            The user ID
1078
        reason : Optional[:class:`str`]
1079
            The reason for unbanning the user |default| :data:`None`
1080
        """
1081
        await self._http.delete(
1082
            f"guilds/{self.id}/bans/{id}",
1083
            headers={"X-Audit-Log-Reason": reason},
1084
        )
1085
1086
    @overload
1087
    async def edit(
0 ignored issues
show
Comprehensibility introduced by
This function exceeds the maximum number of variables (20/15).
Loading history...
1088
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1089
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1090
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1091
        region: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1092
        verification_level: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1093
        default_message_notifications: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1094
        explicit_content_filter: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1095
        afk_channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1096
        afk_timeout: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1097
        icon: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1098
        owner_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1099
        splash: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1100
        discovery_splash: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1101
        banner: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1102
        system_channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1103
        system_channel_flags: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1104
        rules_channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1105
        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...
1106
        preferred_locale: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1107
        features: Optional[List[GuildFeature]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1108
        description: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1109
    ) -> Guild:
1110
        """|coro|
1111
        Modifies the guild
1112
1113
        Parameters
1114
        ----------
1115
        name : Optional[:class:`str`]
1116
            Guild name |default| :data:`None`
1117
        region : Optional[:class:`str`]
1118
            Guild voice region ID |default| :data:`None`
1119
        verification_level : Optional[:class:`int`]
1120
            Verification level |default| :data:`None`
1121
        default_message_notifications : Optional[:class:`int`]
1122
            Default message notification level |default| :data:`None`
1123
        explicit_content_filter : Optional[:class:`int`]
1124
            Explicit content filter level |default| :data:`None`
1125
        afk_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
1126
            ID for AFK channel |default| :data:`None`
1127
        afk_timeout : Optional[:class:`int`]
1128
            AFK timeout in seconds |default| :data:`None`
1129
        icon : Optional[:class:`str`]
1130
            base64 1024x1024 png/jpeg/gif image for the guild icon
1131
            (can be animated gif when the server
1132
            has the `ANIMATED_ICON` feature) |default| :data:`None`
1133
        owner_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
1134
            User ID to transfer guild ownership to (must be owner) |default| :data:`None`
1135
        splash : Optional[:class:`str`]
1136
            base64 16:9 png/jpeg image for the guild splash (when the
1137
            server has the `INVITE_SPLASH` feature) |default| :data:`None`
1138
        discovery_splash : Optional[:class:`str`]
1139
            base64 16:9 png/jpeg image for the guild discovery splash
1140
            (when the server has the `DISCOVERABLE` feature) |default| :data:`None`
1141
        banner : Optional[:class:`str`]
1142
            base64 16:9 png/jpeg image for the guild banner (when the
1143
            server has the `BANNER` feature) |default| :data:`None`
1144
        system_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
1145
            The ID of the channel where guild notices such as welcome
1146
            messages and boost events are posted |default| :data:`None`
1147
        system_channel_flags : Optional[:class:`int`]
1148
            System channel flags |default| :data:`None`
1149
        rules_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
1150
            The ID of the channel where Community guilds display rules
1151
            and/or guidelines |default| :data:`None`
1152
        public_updates_channel_id : Optional[:class:`~pincer.utils.snowflake.Snowflake`]
1153
            The ID of the channel where admins and moderators of
1154
            Community guilds receive notices from Discord |default| :data:`None`
1155
        preferred_locale : Optional[:class:`str`]
1156
            The preferred locale of a Community guild used in server
1157
            discovery and notices from Discord; defaults to "en-US" |default| :data:`None`
1158
        features : Optional[List[:class:`GuildFeature`]]
1159
            Enabled guild features |default| :data:`None`
1160
        description : Optional[:class:`str`]
1161
            The description for the guild, if the guild is discoverable |default| :data:`None`
1162
1163
        Returns
1164
        -------
1165
        :class:`~pincer.objects.guild.Guild`
1166
            The modified guild object.
1167
        """
1168
        ...
1169
1170
    async def edit(self, **kwargs) -> Guild:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
1171
        g = await self._http.patch(f"guilds/{self.id}", data=kwargs)
1172
        return Guild.from_dict(g)
1173
1174
    async def preview(self) -> GuildPreview:
1175
        """|coro|
1176
        Previews the guild.
1177
1178
        Returns
1179
        -------
1180
        :class:`~pincer.objects.guild.guild.GuildPreview`
1181
            The guild preview object.
1182
        """
1183
        data = await self._http.get(f"guilds/{self.id}/preview")
1184
        return GuildPreview.from_dict(data)
1185
1186
    async def delete(self):
1187
        """|coro|
1188
        Deletes the guild. Returns `204 No Content` on success.
1189
        """
1190
        await self._http.delete(f"guilds/{self.id}")
1191
1192
    async def prune_count(
1193
        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...
1194
    ) -> int:
1195
        """|coro|
1196
        Returns the number of members that
1197
        would be removed in a prune operation.
1198
        Requires the ``KICK_MEMBERS`` permission.
1199
1200
        Parameters
1201
        ----------
1202
        days : Optional[:class:`int`]
1203
            Number of days to count prune for (1-30) |default| :data:`7`
1204
        include_roles : Optional[:class:`str`]
1205
            Comma-delimited array of Snowflakes;
1206
            role(s) to include |default| :data:`None`
1207
1208
        Returns
1209
        -------
1210
        :class:`int`
1211
            The number of members that would be removed.
1212
        """
1213
        return await self._http.get(
1214
            f"guilds/{self.id}/prune",
1215
            params={"days": days, "include_roles": include_roles},
1216
        )["pruned"]
1217
1218
    async def prune(
1219
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1220
        days: Optional[int] = 7,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1221
        compute_prune_days: Optional[bool] = True,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1222
        include_roles: Optional[List[Snowflake]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1223
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1224
    ) -> int:
1225
        """|coro|
1226
        Prunes members from the guild. Requires the ``KICK_MEMBERS`` permission.
1227
1228
        Parameters
1229
1230
        Parameters
1231
        ----------
1232
        days : Optional[:class:`int`]
1233
            Number of days to prune (1-30) |default| :data:`7`
1234
        compute_prune_days : Optional[:class:`bool`]
1235
            Whether ``pruned`` is returned, discouraged for large guilds
1236
            |default| :data:`True`
1237
        include_roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake`]]
1238
            role(s) to include |default| :data:`None`
1239
        reason : Optional[:class:`str`]
1240
            Reason for the prune |default| :data:`None`
1241
1242
        Returns
1243
        -------
1244
        :class:`int`
1245
            The number of members that were removed.
1246
        """
1247
        return await self._http.post(
1248
            f"guilds/{self.id}/prune",
1249
            data={
1250
                "days": days,
1251
                "compute_prune_days": compute_prune_days,
1252
                "include_roles": include_roles,
1253
            },
1254
            headers={"X-Audit-Log-Reason": reason},
1255
        )["pruned"]
1256
1257
    async def get_voice_regions(self) -> AsyncGenerator[VoiceRegion, None]:
1258
        """|coro|
1259
        Returns an async generator of voice regions.
1260
1261
        Yields
1262
        -------
1263
        AsyncGenerator[:class:`~pincer.objects.voice.VoiceRegion`, :data:`None`]
1264
            An async generator of voice regions.
1265
        """
1266
        data = await self._http.get(f"guilds/{self.id}/regions")
1267
        for voice_region_data in data:
1268
            yield VoiceRegion.from_dict(voice_region_data)
1269
1270
    async def get_invites(self) -> AsyncGenerator[Invite, None]:
1271
        """|coro|
1272
        Returns an async generator of invites for the guild.
1273
        Requires the ``MANAGE_GUILD`` permission.
1274
1275
        Yields
1276
        -------
1277
        AsyncGenerator[:class:`~pincer.objects.invite.Invite`, :data:`None`]
1278
            An async generator of invites.
1279
        """
1280
        data = await self._http.get(f"guilds/{self.id}/invites")
1281
        for invite_data in data:
1282
            yield Invite.from_dict(invite_data)
1283
1284
    async def get_invite(self, code: str) -> Invite:
1285
        """|coro|
1286
        Returns an Invite object for the given invite code.
1287
1288
        Parameters
1289
        ----------
1290
        code : :class:`str`
1291
            The invite code to get the invite for.
1292
1293
        Returns
1294
        -------
1295
        :class:`~pincer.objects.guild.invite.Invite`
1296
            The invite object.
1297
        """
1298
        data = await self._http.get(f"invite/{code}")
1299
        return Invite.from_dict(data)
1300
1301
    async def get_integrations(self) -> AsyncIterator[Integration]:
0 ignored issues
show
introduced by
Value 'AsyncIterator' is unsubscriptable
Loading history...
1302
        """|coro|
1303
        Returns an async generator of integrations for the guild.
1304
        Requires the ``MANAGE_GUILD`` permission.
1305
1306
        Yields
1307
        -------
1308
        AsyncGenerator[:class:`~pincer.objects.integration.Integration`, :data:`None`]
1309
            An async generator of integrations.
1310
        """
1311
        data = await self._http.get(f"guilds/{self.id}/integrations")
1312
        for integration_data in data:
1313
            yield Integration.from_dict(integration_data)
1314
1315
    async def delete_integration(
1316
        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...
1317
    ):
1318
        """|coro|
1319
        Deletes an integration.
1320
        Requires the ``MANAGE_GUILD`` permission.
1321
1322
        Parameters
1323
        ----------
1324
        integration : :class:`~pincer.objects.integration.Integration`
1325
            The integration to delete.
1326
        reason : Optional[:class:`str`]
1327
            Reason for the deletion |default| :data:`None`
1328
        """
1329
        await self._http.delete(
1330
            f"guilds/{self.id}/integrations/{integration.id}",
1331
            headers={"X-Audit-Log-Reason": reason},
1332
        )
1333
1334
    async def delete_invite(self, code: str):
1335
        """|coro|
1336
        Deletes an invite.
1337
        Requires the ``MANAGE_GUILD`` intent.
1338
1339
        Parameters
1340
        ----------
1341
        code : :class:`str`
1342
            The code of the invite to delete.
1343
        """
1344
        await self._http.delete(f"guilds/{self.id}/invites/{code}")
1345
1346
    async def get_widget_settings(self) -> GuildWidget:
1347
        """|coro|
1348
        Returns the guild widget settings.
1349
        Requires the ``MANAGE_GUILD`` permission.
1350
1351
        Returns
1352
        -------
1353
        :class:`~pincer.objects.guild.widget.GuildWidget`
1354
            The guild widget settings.
1355
        """
1356
        return GuildWidget.from_dict(
1357
            await self._http.get(f"guilds/{self.id}/widget")
1358
        )
1359
1360
    async def modify_widget(
1361
        self, reason: Optional[str] = None, **kwargs
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1362
    ) -> GuildWidget:
1363
        """|coro|
1364
        Modifies the guild widget for the guild.
1365
        Requires the ``MANAGE_GUILD`` permission.
1366
1367
        Parameters
1368
        ----------
1369
        reason : Optional[:class:`str`]
1370
            Reason for the modification |default| :data:`None`
1371
        \\*\\*kwargs
1372
            The widget settings to modify
1373
1374
        Returns
1375
        -------
1376
        :class:`~pincer.objects.guild.widget.GuildWidget`
1377
            The updated GuildWidget object
1378
        """
1379
        data = await self._http.patch(
1380
            f"guilds/{self.id}/widget",
1381
            data=kwargs,
1382
            headers={"X-Audit-Log-Reason": reason},
1383
        )
1384
        return GuildWidget.from_dict(data)
1385
1386
    async def get_widget(self) -> Dict[str, JSONSerializable]:
1387
        """|coro|
1388
        Returns the widget for the guild
1389
        """
1390
        return await self._http.get(f"guilds/{self.id}/widget.json")
1391
1392
    @property
1393
    async def vanity_url(self) -> Invite:
1394
        """|coro|
1395
        Returns the Vanity URL for the guild.
1396
        Requires the ``MANAGE_GUILD`` permission.
1397
        ``code`` will be null if a vanity URL has not been set.
1398
1399
        Returns
1400
        -------
1401
        :class:`~pincer.objects.guild.invite.Invite`
1402
            The vanity url for the guild.
1403
        """
1404
        data = await self._http.get(f"guilds/{self.id}/vanity-url")
1405
        return Invite.from_dict(data)
1406
1407
    async def get_widget_image(
1408
        self, style: Optional[str] = "shield"
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1409
    ) -> 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...
1410
        """|coro|
1411
        Returns a PNG image widget for the guild.
1412
        Requires no permissions or authentication.
1413
1414
        Widget Style Options
1415
        -------------------
1416
        * [``shield``](https://discord.com/api/guilds/81384788765712384/widget.png?style=shield)
1417
          shield style widget with Discord icon and guild members online count
1418
        * [``banner1``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner1)
1419
          large image with guild icon, name and online count.
1420
          "POWERED BY DISCORD" as the footer of the widget
1421
        * [``banner2``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner2)
1422
          smaller widget style with guild icon, name and online count.
1423
          Split on the right with Discord logo
1424
        * [``banner3``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner3)
1425
          large image with guild icon, name and online count.
1426
          In the footer, Discord logo on the
1427
          left and "Chat Now" on the right
1428
        * [``banner4``](https://discord.com/api/guilds/81384788765712384/widget.png?style=banner4)
1429
          large Discord logo at the top of the widget.
1430
          Guild icon, name and online count in the middle portion
1431
          of the widget and a "JOIN MY SERVER" button at the bottom
1432
1433
        Parameters
1434
        ----------
1435
        style : Optional[:class:`str`]
1436
            Style of the widget image returned |default| :data:`"shield"`
1437
1438
        Returns
1439
        -------
1440
        :class:`str`
1441
            A PNG image of the guild widget.
1442
        """
1443
        return await self._http.get(f"guilds/{self.id}/widget.png?{style=!s}")
1444
1445
    async def get_welcome_screen(self) -> WelcomeScreen:
1446
        """Returns the welcome screen for the guild.
1447
1448
        Returns
1449
        -------
1450
        :class:`~pincer.objects.guild.welcome_screen.WelcomeScreen`
1451
            The welcome screen for the guild.
1452
        """
1453
        data = await self._http.get(f"guilds/{self.id}/welcome-screen")
1454
        return WelcomeScreen.from_dict(data)
1455
1456
    async def modify_welcome_screen(
1457
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1458
        enabled: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1459
        welcome_channels: Optional[List[WelcomeScreenChannel]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1460
        description: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1461
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1462
    ) -> WelcomeScreen:
1463
        """|coro|
1464
        Modifies the guild's Welcome Screen.
1465
        Requires the ``MANAGE_GUILD`` permission.
1466
1467
        Parameters
1468
        ----------
1469
        enabled : Optional[:class:`bool`]
1470
            Whether the welcome screen is enabled |default| :data:`None`
1471
        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...
1472
            Channels linked in the welcome screen and
1473
            their display options |default| :data:`None`
1474
        description : Optional[:class:`str`]
1475
            The server description to show
1476
            in the welcome screen |default| :data:`None`
1477
        reason : Optional[:class:`str`]
1478
            Reason for the modification |default| :data:`None`
1479
1480
        Returns
1481
        -------
1482
        :class:`~pincer.objects.guild.welcome_screen.WelcomeScreen`
1483
            The updated WelcomeScreen object
1484
        """
1485
        data = await self._http.patch(
1486
            f"guilds/{self.id}/welcome-screen",
1487
            data={
1488
                "enabled": enabled,
1489
                "welcome_channels": welcome_channels,
1490
                "description": description,
1491
            },
1492
            headers={"X-Audit-Log-Reason": reason},
1493
        )
1494
        return WelcomeScreen.from_dict(data)
1495
1496
    async def modify_current_user_voice_state(
1497
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1498
        channel_id: Snowflake,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1499
        suppress: Optional[bool] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1500
        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...
1501
    ):
1502
        """|coro|
1503
        Updates the current user's voice state.
1504
1505
        There are currently several caveats for this endpoint:
1506
        * ``channel_id`` must currently point to a stage channel
1507
        * current user must already have joined ``channel_id``
1508
        * You must have the ``MUTE_MEMBERS`` permission to
1509
          unsuppress yourself. You can always suppress yourself.
1510
        * You must have the ``REQUEST_TO_SPEAK`` permission to request
1511
          to speak. You can always clear your own request to speak.
1512
        * You are able to set ``request_to_speak_timestamp`` to any
1513
          present or future time.
1514
1515
        Parameters
1516
        ----------
1517
        channel_id : :class:`~pincer.utils.snowflake.Snowflake`
1518
            The ID of the channel the user is currently in
1519
        suppress : Optional[:class:`bool`]
1520
            Toggles the user's suppress state |default| :data:`None`
1521
        request_to_speak_timestamp : Optional[:class:`~pincer.utils.timestamp.Timestamp`]
1522
            Sets the user's request to speak
1523
        """
1524
        await self._http.patch(
1525
            f"guilds/{self.id}/voice-states/@me",
1526
            data={
1527
                "channel_id": channel_id,
1528
                "suppress": suppress,
1529
                "request_to_speak_timestamp": request_to_speak_timestamp,
1530
            },
1531
        )
1532
1533
    async def modify_user_voice_state(
1534
        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...
1535
    ):
1536
        """|coro|
1537
        Updates another user's voice state.
1538
1539
        There are currently several caveats for this endpoint:
1540
        * ``channel_id`` must currently point to a stage channel
1541
        * User must already have joined ``channel_id``
1542
        * You must have the ``MUTE_MEMBERS`` permission.
1543
          (Since suppression is the only thing that is available currently.)
1544
        * When unsuppressed, non-bot users will have their
1545
          ``request_to_speak_timestamp`` set to the current time.
1546
          Bot users will not.
1547
        * When suppressed, the user will have their
1548
          ``request_to_speak_timestamp`` removed.
1549
1550
        Parameters
1551
        ----------
1552
        user : :class:`~pincer.objects.guild.member.Member`
1553
            The user to update
1554
        channel_id : :class:`~pincer.utils.snowflake.Snowflake`
1555
            The ID of the channel the user is currently in
1556
        suppress : Optional[:class:`bool`]
1557
            Toggles the user's suppress state |default| :data:`None`
1558
        """
1559
        await self._http.patch(
1560
            f"guilds/{self.id}/voice-states/{user.id}",
1561
            data={"channel_id": channel_id, "suppress": suppress},
1562
        )
1563
1564
    async def get_audit_log(self) -> AuditLog:
1565
        """|coro|
1566
        Returns an audit log object for the guild.
1567
        Requires the ``VIEW_AUDIT_LOG`` permission.
1568
1569
        Returns
1570
        -------
1571
        :class:`~pincer.objects.guild.audit_log.AuditLog`
1572
            The audit log object for the guild.
1573
        """
1574
        return AuditLog.from_dict(
1575
            await self._http.get(f"guilds/{self.id}/audit-logs")
1576
        )
1577
1578
    async def get_emojis(self) -> AsyncGenerator[Emoji, None]:
1579
        """|coro|
1580
        Returns an async generator of the emojis in the guild.
1581
1582
        Yields
1583
        ------
1584
        :class:`~pincer.objects.guild.emoji.Emoji`
1585
            The emoji object.
1586
        """
1587
        data = await self._http.get(f"guilds/{self.id}/emojis")
1588
        for emoji_data in data:
1589
            yield Emoji.from_dict(emoji_data)
1590
1591
    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...
1592
        """|coro|
1593
        Returns an emoji object for the given ID.
1594
1595
        Parameters
1596
        ----------
1597
        id : :class:`~pincer.utils.snowflake.Snowflake`
1598
            The ID of the emoji
1599
1600
        Returns
1601
        -------
1602
        :class:`~pincer.objects.guild.emoji.Emoji`
1603
            The emoji object.
1604
        """
1605
        return Emoji.from_dict(
1606
            await self._http.get(f"guilds/{self.id}/emojis/{id}")
1607
        )
1608
1609
    async def create_emoji(
1610
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1611
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1612
        name: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1613
        image: File,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1614
        roles: Optional[List[Snowflake]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1615
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1616
    ) -> Emoji:
1617
        """|coro|
1618
        Creates a new emoji for the guild.
1619
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1620
1621
        Emojis and animated emojis have a maximum file size of 256kb.
1622
        Attempting to upload an emoji larger than this limit will fail.
1623
1624
        Parameters
1625
        ----------
1626
        name : :class:`str`
1627
            Name of the emoji
1628
        image : :class:`~pincer.objects.message.file.File`
1629
            The File for the 128x128 emoji image data
1630
        roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake`]]
1631
            Roles allowed to use this emoji |default| :data:`[]`
1632
        reason : Optional[:class:`str`]
1633
            The reason for creating the emoji |default| :data:`None`
1634
1635
        Returns
1636
        -------
1637
        :class:`~pincer.objects.guild.emoji.Emoji`
1638
            The newly created emoji object.
1639
        """
1640
        roles = [] if roles is None else roles
1641
1642
        data = await self._http.post(
1643
            f"guilds/{self.id}/emojis",
1644
            data={"name": name, "image": image.uri, "roles": roles},
1645
            headers={"X-Audit-Log-Reason": reason},
1646
        )
1647
        return Emoji.from_dict(data)
1648
1649
    async def edit_emoji(
1650
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1651
        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...
1652
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1653
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1654
        roles: Optional[List[Snowflake]] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1655
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1656
    ) -> Emoji:
1657
        """|coro|
1658
        Modifies the given emoji.
1659
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1660
1661
        Parameters
1662
        ----------
1663
        id : :class:`~pincer.utils.snowflake.Snowflake`
1664
            The ID of the emoji
1665
        name : Optional[:class:`str`]
1666
            Name of the emoji |default| :data:`None`
1667
        roles : Optional[List[:class:`~pincer.utils.snowflake.Snowflake`]]
1668
            Roles allowed to use this emoji |default| :data:`None`
1669
        reason : Optional[:class:`str`]
1670
            The reason for editing the emoji |default| :data:`None`
1671
1672
        Returns
1673
        -------
1674
        :class:`~pincer.objects.guild.emoji.Emoji`
1675
            The modified emoji object.
1676
        """
1677
        data = await self._http.patch(
1678
            f"guilds/{self.id}/emojis/{id}",
1679
            data={"name": name, "roles": roles},
1680
            headers={"X-Audit-Log-Reason": reason},
1681
        )
1682
        return Emoji.from_dict(data)
1683
1684
    async def delete_emoji(
1685
        self, id: Snowflake, *, reason: Optional[str] = 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 id.

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

Loading history...
1686
    ):
1687
        """|coro|
1688
        Deletes the given emoji.
1689
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1690
1691
        Parameters
1692
        ----------
1693
        id : :class:`~pincer.utils.snowflake.Snowflake`
1694
            The ID of the emoji
1695
        reason : Optional[:class:`str`]
1696
            The reason for deleting the emoji |default| :data:`None`
1697
        """
1698
        await self._http.delete(
1699
            f"guilds/{self.id}/emojis/{id}",
1700
            headers={"X-Audit-Log-Reason": reason},
1701
        )
1702
1703
    async def get_templates(self) -> AsyncIterator[GuildTemplate]:
0 ignored issues
show
introduced by
Value 'AsyncIterator' is unsubscriptable
Loading history...
1704
        """|coro|
1705
        Returns an async generator of the guild templates.
1706
1707
        Yields
1708
        -------
1709
        AsyncGenerator[:class:`~pincer.objects.guild.template.GuildTemplate`, :data:`None`]
1710
            The guild template object.
1711
        """
1712
        data = await self._http.get(f"guilds/{self.id}/templates")
1713
        for template_data in data:
1714
            yield GuildTemplate.from_dict(template_data)
1715
1716
    async def create_template(
1717
        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...
1718
    ) -> GuildTemplate:
1719
        """|coro|
1720
        Creates a new template for the guild.
1721
        Requires the ``MANAGE_GUILD`` permission.
1722
1723
        Parameters
1724
        ----------
1725
        name : :class:`str`
1726
            Name of the template (1-100 characters)
1727
        description : Optional[:class:`str`]
1728
            Description of the template
1729
            (0-120 characters) |default| :data:`None`
1730
        Returns
1731
        -------
1732
        :class:`~pincer.objects.guild.template.GuildTemplate`
1733
            The newly created template object.
1734
        """
1735
        data = await self._http.post(
1736
            f"guilds/{self.id}/templates",
1737
            data={"name": name, "description": description},
1738
        )
1739
        return GuildTemplate.from_dict(data)
1740
1741
    async def sync_template(self, template: GuildTemplate) -> GuildTemplate:
1742
        """|coro|
1743
        Syncs the given template.
1744
        Requires the ``MANAGE_GUILD`` permission.
1745
1746
        Parameters
1747
        ----------
1748
        template : :class:`~pincer.objects.guild.template.GuildTemplate`
1749
            The template to sync
1750
1751
        Returns
1752
        -------
1753
        :class:`~pincer.objects.guild.template.GuildTemplate`
1754
            The synced template object.
1755
        """
1756
        data = await self._http.put(
1757
            f"guilds/{self.id}/templates/{template.code}"
1758
        )
1759
        return GuildTemplate.from_dict(data)
1760
1761
    async def edit_template(
1762
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1763
        template: GuildTemplate,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1764
        *,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1765
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1766
        description: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1767
    ) -> GuildTemplate:
1768
        """|coro|
1769
        Modifies the template's metadata.
1770
        Requires the ``MANAGE_GUILD`` permission.
1771
1772
        Parameters
1773
        ----------
1774
        template : :class:`~pincer.objects.guild.template.GuildTemplate`
1775
            The template to edit
1776
        name : Optional[:class:`str`]
1777
            Name of the template (1-100 characters)
1778
            |default| :data:`None`
1779
        description : Optional[:class:`str`]
1780
            Description of the template (0-120 characters)
1781
            |default| :data:`None`
1782
1783
        Returns
1784
        -------
1785
        :class:`~pincer.objects.guild.template.GuildTemplate`
1786
            The edited template object.
1787
        """
1788
        data = await self._http.patch(
1789
            f"guilds/{self.id}/templates/{template.code}",
1790
            data={"name": name, "description": description},
1791
        )
1792
        return GuildTemplate.from_dict(data)
1793
1794
    async def delete_template(self, template: GuildTemplate) -> GuildTemplate:
1795
        """|coro|
1796
        Deletes the given template.
1797
        Requires the ``MANAGE_GUILD`` permission.
1798
1799
        Parameters
1800
        ----------
1801
        template : :class:`~pincer.objects.guild.template.GuildTemplate`
1802
            The template to delete
1803
1804
        Returns
1805
        -------
1806
        :class:`~pincer.objects.guild.template.GuildTemplate`
1807
            The deleted template object.
1808
        """
1809
        data = await self._http.delete(
1810
            f"guilds/{self.id}/templates/{template.code}"
1811
        )
1812
        return GuildTemplate.from_dict(data)
1813
1814
    async def list_stickers(self) -> AsyncIterator[Sticker]:
0 ignored issues
show
introduced by
Value 'AsyncIterator' is unsubscriptable
Loading history...
1815
        """|coro|
1816
        Yields sticker objects for the current guild.
1817
        Includes ``user`` fields if the bot has the
1818
        ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1819
1820
        Yields
1821
        ------
1822
        :class:`~pincer.objects.message.sticker.Sticker`
1823
            a sticker for the current guild
1824
        """
1825
1826
        for sticker in await self._http.get(f"guild/{self.id}/stickers"):
1827
            yield Sticker.from_dict(sticker)
1828
1829
    async def get_sticker(self, _id: Snowflake) -> Sticker:
1830
        """|coro|
1831
        Returns a sticker object for the current guild and sticker IDs.
1832
        Includes the ``user`` field if the bot has the
1833
        ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1834
1835
        Parameters
1836
        ----------
1837
        _id : int
1838
            id of the sticker
1839
1840
        Returns
1841
        -------
1842
        :class:`~pincer.objects.message.sticker.Sticker`
1843
            the sticker requested
1844
        """
1845
        sticker = await self._http.get(f"guilds/{self.id}/stickers/{_id}")
1846
        return Sticker.from_dict(sticker)
1847
1848
    async def create_sticker(
0 ignored issues
show
best-practice introduced by
Too many arguments (6/5)
Loading history...
1849
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1850
        name: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1851
        tags: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1852
        description: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1853
        file: File,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1854
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1855
    ) -> Sticker:
1856
        """|coro|
1857
        Create a new sticker for the guild.
1858
        Requires the ``MANAGE_EMOJIS_AND_STICKERS permission``.
1859
1860
        Parameters
1861
        ----------
1862
        name : str
1863
            name of the sticker (2-30 characters)
1864
        tags : str
1865
            autocomplete/suggestion tags for the sticker (max 200 characters)
1866
        file : :class:`~pincer.objects.message.file.File`
1867
            the sticker file to upload, must be a PNG, APNG, or Lottie JSON file, max 500 KB
1868
        description : str
1869
            description of the sticker (empty or 2-100 characters) |default| :data:`""`
1870
        reason : Optional[:class:`str`] |default| :data:`None`
1871
            reason for creating the sticker
1872
1873
        Returns
1874
        -------
1875
        :class:`~pincer.objects.message.sticker.Sticker`
1876
            the newly created sticker
1877
        """  # noqa: E501
1878
1879
        form = FormData()
1880
        form.add_field("name", name)
1881
        form.add_field("tags", tags)
1882
        form.add_field("description", description)
1883
        form.add_field("file", file.content, content_type=file.content_type)
1884
1885
        payload = form()
1886
1887
        sticker = await self._http.post(
1888
            f"guilds/{self.id}/stickers",
1889
            data=payload,
1890
            headers={"X-Audit-Log-Reason": reason},
1891
            content_type=payload.content_type,
1892
        )
1893
1894
        return Sticker.from_dict(sticker)
1895
1896
    async def delete_sticker(self, _id: Snowflake):
1897
        """|coro|
1898
        Delete the given sticker.
1899
        Requires the ``MANAGE_EMOJIS_AND_STICKERS`` permission.
1900
1901
        Parameters
1902
        ----------
1903
        _id: Snowflake
1904
            id of the sticker
1905
        """
1906
        await self._http.delete(f"guilds/{self.id}/stickers/{_id}")
1907
1908
    async def get_webhooks(self) -> AsyncGenerator[Webhook, None]:
1909
        """|coro|
1910
        Returns an async generator of the guild webhooks.
1911
1912
        Yields
1913
        -------
1914
        AsyncGenerator[:class:`~pincer.objects.guild.webhook.Webhook`, None]
1915
            The guild webhook object.
1916
        """
1917
        data = await self._http.get(f"guilds/{self.id}/webhooks")
1918
        for webhook_data in data:
1919
            yield Webhook.from_dict(webhook_data)
1920
1921
    async def get_scheduled_events(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
1922
        self, with_user_count: bool = False
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1923
        ) -> AsyncGenerator[ScheduledEvent, None]:
1924
        data = await self._http.get(f"guilds/{self.id}/scheduled-events?{with_user_count=!s}")
1925
        for event_data in data:
1926
            yield ScheduledEvent.from_dict(
1927
                construct_client_dict(self._client, event_data)
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'construct_client_dict'
Loading history...
1928
            )
1929
1930
    async def create_scheduled_event(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
best-practice introduced by
Too many arguments (10/5)
Loading history...
1931
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1932
        name: str,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1933
        privacy_level: int,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1934
        entity_type: int,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1935
        scheduled_start_time: datetime,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1936
        scheduled_end_time: Optional[datetime] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1937
        entity_metadata: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1938
        channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1939
        description: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1940
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1941
    ) -> ScheduledEvent:
1942
        if scheduled_start_time.timestamp() < datetime.now().timestamp():
1943
            raise ValueError("An event cannot be created in the past")
1944
1945
        if scheduled_end_time is not None and scheduled_end_time.timestamp() < datetime.now().timestamp():
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (106/100).

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

Loading history...
1946
            raise ValueError("An event cannot start before it ends")
1947
1948
        data = await self._http.post(
1949
            f"guilds/{self.id}/scheduled-events",
1950
            data={
1951
                "name": name,
1952
                "privacy_level": privacy_level,
1953
                "entity_type": entity_type,
1954
                "scheduled_start_time": scheduled_start_time.isoformat(),
1955
                "scheduled_end_time": scheduled_end_time.isoformat() if scheduled_end_time is not None else None,
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (113/100).

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

Loading history...
1956
                "entity_metadata": entity_metadata,
1957
                "channel_id": channel_id,
1958
                "description": description,
1959
                },
1960
            headers={"X-Audit-Log-Reason": reason},
1961
            )
1962
        return ScheduledEvent.from_dict(
1963
            construct_client_dict(self._client, data)
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'construct_client_dict'
Loading history...
1964
        )
1965
1966
    async def get_scheduled_event(self, _id: Snowflake, with_user_count: bool = False) -> ScheduledEvent:
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (105/100).

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

Loading history...
introduced by
Missing function or method docstring
Loading history...
1967
        data = await self._http.get(f"guilds/{self.id}/scheduled-events/{_id}?{with_user_count=!s}")
1968
        return ScheduledEvent.from_dict(
1969
            construct_client_dict(self._client, data)
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'construct_client_dict'
Loading history...
1970
        )
1971
1972
    async def modify_scheduled_event(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
best-practice introduced by
Too many arguments (12/5)
Loading history...
1973
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1974
        _id: Snowflake,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1975
        name: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1976
        entity_type: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1977
        privacy_level: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1978
        scheduled_start_time: Optional[datetime] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1979
        scheduled_end_time: Optional[datetime] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1980
        entity_metadata: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1981
        channel_id: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1982
        description: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1983
        status: Optional[int] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1984
        reason: Optional[str] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
1985
    ) -> ScheduledEvent:
1986
        if scheduled_start_time is not None and scheduled_start_time.timestamp() < datetime.now().timestamp():
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (110/100).

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

Loading history...
1987
            raise ValueError("An event cannot be created in the past")
1988
1989
        if scheduled_end_time is not None and scheduled_end_time.timestamp() < datetime.now().timestamp():
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (106/100).

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

Loading history...
1990
            raise ValueError("An event cannot start before it ends")
1991
1992
        kwargs: Dict[str, str] = remove_none({
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'remove_none'
Loading history...
1993
            "name": name,
1994
            "privacy_level": privacy_level,
1995
            "entity_type": entity_type,
1996
            "scheduled_start_time": scheduled_start_time.isoformat() if scheduled_start_time is not None else None,
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (115/100).

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

Loading history...
1997
            "scheduled_end_time": scheduled_end_time.isoformat() if scheduled_end_time is not None else None,
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...
1998
            "entity_metadata": entity_metadata,
1999
            "channel_id": channel_id,
2000
            "description": description,
2001
            "status": status,
2002
            })
2003
2004
        data = await self._http.patch(
2005
            f"guilds/{self.id}/scheduled-events/{_id}",
2006
            data=kwargs,
2007
            headers={"X-Audit-Log-Reason": reason},
2008
            )
2009
        return ScheduledEvent.from_dict(
2010
            construct_client_dict(self._client, data)
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'construct_client_dict'
Loading history...
2011
        )
2012
2013
    async def delete_scheduled_event(self, _id: Snowflake):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
2014
        await self._http.delete(f"guilds/{self.id}/scheduled-events/{_id}")
2015
2016
    async def get_guild_scheduled_event_users(
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
2017
        self,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
2018
        _id: Snowflake,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
2019
        limit: int = 100,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
2020
        with_member: bool = False,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
2021
        before: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
2022
        after: Optional[Snowflake] = None,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
2023
        ) -> AsyncGenerator[GuildScheduledEventUser, None]:
2024
        url = f"guilds/{self.id}/scheduled-events/{_id}/users?{limit=!s}&{with_member=!s}"
2025
2026
        if before is not None:
2027
            url += f"&{before!s}"
2028
        if after is not None:
2029
            url += f"&{after!s}"
2030
2031
        data = await self._http.get(url)
2032
2033
        for user_data in data:
2034
            yield GuildScheduledEventUser.from_dict(
2035
                construct_client_dict(self._client, user_data)
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'construct_client_dict'
Loading history...
2036
            )
2037
2038
    @classmethod
2039
    def from_dict(cls, data) -> Guild:
2040
        """
2041
        Parameters
2042
        ----------
2043
        data : :class:`Dict`
2044
            Guild data received from the discord API.
2045
        Returns
2046
        -------
2047
        :class:`~pincer.objects.guild.guild.Guild`
2048
            The new guild object.
2049
        Raises
2050
        ------
2051
        :class:`~pincer.exceptions.UnavailableGuildError`
2052
            The guild is unavailable due to a discord outage.
2053
        """
2054
        if data.get("unavailable", False):
2055
            raise UnavailableGuildError(
2056
                f"Guild \"{data['id']}\" is unavailable due to a discord"
2057
                " outage."
2058
            )
2059
2060
        return super().from_dict(data)
2061
2062
2063
@dataclass(repr=False)
2064
class UnavailableGuild(APIObject):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
2065
    id: Snowflake
2066
    unavailable: bool = True
2067