def get_prefix(bot: Bot, message: Message) -> List[str]:
    prefixes = []
    match_nickname: Optional[Match] = NICKNAME_PATTERN.match(
        message.guild.me.display_name
    )
    if match_nickname:
        prefixes.append(match_nickname.group(1))
    if str(message.guild.id) in prefix_dict.keys():
        prefixes.append(prefix_dict[str(message.guild.id)])
    if not prefixes:
        prefixes: List[str] = [const.BOT_PREFIX]
    return when_mentioned_or(*prefixes)(bot, message)
Example #2
0
File: bot.py Project: kemp42/Milton
async def _get_prefix(bot: Milton, message: discord.Message) -> Callable:
    """Returns the function to correctly get the prefix based on context.

    Attributes:
        bot: The bot to get the prefox for
        message: The message that is triggering the prefix retrieving.

    Returns:
        A callable function that returns the prefix.
    """
    if isinstance(message.channel, PrivateChannel):
        return when_mentioned(bot, message)
    return when_mentioned_or(CONFIG.prefixes.guild)(bot, message)
Example #3
0
from discord.ext.commands.bot import when_mentioned_or
import discord
from discord.ext import commands
from discord.ext.commands import Cog

intents = discord.Intents.default()
intents.members = True
intents.messages = True
intents.bans = True

bot = commands.Bot(command_prefix=when_mentioned_or("tb!"), intents=intents)


class Admin(Cog):
    def __init__(self, bot):
        self.bot = bot

    @commands.command()
    @commands.has_permissions(ban_members=True)
    async def ban(self, ctx, member: discord.Member, *, reason=None):
        await member.ban(reason=reason)
        await ctx.send(f'{member} banlandı!')

    # The below code unbans player.
    @commands.command()
    @commands.has_permissions(administrator=True)
    async def unban(self, ctx, *, member):
        banned_users = await ctx.guild.bans()
        member_name, member_discriminator = member.split("#")

        for ban_entry in banned_users:
Example #4
0
async def prefix(bot, ctx):
    try:
        return when_mentioned_or(bot.config[str(ctx.guild.id)]["prefix"])(bot,
                                                                          ctx)
    except KeyError:
        return when_mentioned_or(default_prefix)(bot, ctx)
Example #5
0
 def __init__(self):
     super().__init__(command_prefix=when_mentioned_or(PREFIX), description= "MEC Covid19 Tracking Project!")
     self.load_cogs()
Example #6
0
        content = None
        if isinstance(error, commands.CommandInvokeError):
            error = error.original
        if isinstance(error, commands.NotOwner):
            content = "あなたにこのコマンドを実行する権限がありません!\nYou don't have permission."
        elif isinstance(error, commands.BadArgument):
            content = "不正な引数です!\nInvalid argument passed."
        elif isinstance(error, commands.MissingRequiredArgument):
            content = "想定しない引数が渡されました!\nInvalid input."
        elif isinstance(error, commands.TooManyArguments):
            content = "引数の数が不正です!\nInvalid input."
        elif isinstance(error, commands.CommandNotFound):
            content = "存在しないコマンドです。\nThe command is not available."
        elif isinstance(error, discord.HTTPException):
            if error.code == 10008:
                content = "メッセージが見つかりませんでした。"
            elif error.code == 10014:
                content = "絵文字が見つかりませんでした。"
        if content is None:
            content = f"不明なエラーが発生しました。\nエラー内容:\n{error}"
        embed = discord.Embed(
            title="Error", description=content, color=0xff0000)
        await ctx.message.delete()
        await ctx.send(embed=embed)


if __name__ == '__main__':
    prefixes = [PREFIX, "ab.", "a!", "a."]
    bot = Abacus(command_prefix=when_mentioned_or(*prefixes))
    bot.run(TOKEN)