discord.py 2.0 update (3d914e08->2.0.1) (#5709)

This commit is contained in:
Jakub Kuczys
2022-10-03 16:07:15 +02:00
committed by GitHub
parent d7d6ab46f4
commit f02528378f
44 changed files with 454 additions and 317 deletions

View File

@@ -1,6 +1,6 @@
import asyncio
import logging
from typing import Tuple
from typing import Tuple, Union
import discord
from redbot.core import Config, checks, commands
@@ -153,7 +153,7 @@ class Admin(commands.Cog):
async def _addrole(
self, ctx: commands.Context, member: discord.Member, role: discord.Role, *, check_user=True
):
if role in member.roles:
if member.get_role(role.id) is not None:
await ctx.send(
_("{member.display_name} already has the role {role.name}.").format(
role=role, member=member
@@ -183,7 +183,7 @@ class Admin(commands.Cog):
async def _removerole(
self, ctx: commands.Context, member: discord.Member, role: discord.Role, *, check_user=True
):
if role not in member.roles:
if member.get_role(role.id) is None:
await ctx.send(
_("{member.display_name} does not have the role {role.name}.").format(
role=role, member=member
@@ -214,7 +214,11 @@ class Admin(commands.Cog):
@commands.guild_only()
@checks.admin_or_permissions(manage_roles=True)
async def addrole(
self, ctx: commands.Context, rolename: discord.Role, *, user: discord.Member = None
self,
ctx: commands.Context,
rolename: discord.Role,
*,
user: discord.Member = commands.Author,
):
"""
Add a role to a user.
@@ -222,15 +226,17 @@ class Admin(commands.Cog):
Use double quotes if the role contains spaces.
If user is left blank it defaults to the author of the command.
"""
if user is None:
user = ctx.author
await self._addrole(ctx, user, rolename)
@commands.command()
@commands.guild_only()
@checks.admin_or_permissions(manage_roles=True)
async def removerole(
self, ctx: commands.Context, rolename: discord.Role, *, user: discord.Member = None
self,
ctx: commands.Context,
rolename: discord.Role,
*,
user: discord.Member = commands.Author,
):
"""
Remove a role from a user.
@@ -238,8 +244,6 @@ class Admin(commands.Cog):
Use double quotes if the role contains spaces.
If user is left blank it defaults to the author of the command.
"""
if user is None:
user = ctx.author
await self._removerole(ctx, user, rolename)
@commands.group()
@@ -349,7 +353,9 @@ class Admin(commands.Cog):
pass
@announceset.command(name="channel")
async def announceset_channel(self, ctx, *, channel: discord.TextChannel):
async def announceset_channel(
self, ctx, *, channel: Union[discord.TextChannel, discord.VoiceChannel]
):
"""Change the channel where the bot will send announcements."""
await self.config.guild(ctx.guild).announce_channel.set(channel.id)
await ctx.send(
@@ -389,7 +395,7 @@ class Admin(commands.Cog):
Server admins must have configured the role as user settable.
NOTE: The role is case sensitive!
"""
if selfrole in ctx.author.roles:
if ctx.author.get_role(selfrole.id) is not None:
return await self._removerole(ctx, ctx.author, selfrole, check_user=False)
else:
return await self._addrole(ctx, ctx.author, selfrole, check_user=False)