async def prefix(self, ctx):
        """Prefix Commands group."""

        prefixes = read_json("prefixes")
        try:
            prefix = prefixes[str(ctx.guild.id)]
        except KeyError:
            prefix = "-"

        embed = discord.Embed(
            title="Prefix Commands",
            description=f"My prefix for this server is `{prefix}`. "
            "I will also respond if you mention me.",
            color=0x0DD9FD,
        )
        embed.set_thumbnail(url=ctx.author.avatar_url)
        embed.add_field(
            name="Changing your servers prefix",
            value="To change your servers prefix, "
            f"run `{prefix}prefix change <newprefix>` "
            "(If it contains a space, you need to surround it with quotations)",
            inline=False,
        )
        embed.add_field(
            name="Resetting your servers prefix",
            value=f"To reset your servers prefix, "
            f"run `{prefix}prefix reset` and your prefix will be changed back to `-`.",
            inline=False,
        )
        await ctx.send(embed=embed)
Beispiel #2
0
async def on_ready():
    data = read_json("blacklist")
    bot.blacklisted = data["blacklisted"]
    print(
        f"Bot is now online.\n"
        f"Logged in as {bot.user.name}\n"
        f"ID: {bot.user.id}\n"
        f"Invite Link: https://discord.com/oauth2/authorize?client_id={bot.user.id}&scope=bot"
    )
    await bot.change_presence(activity=discord.Game(
        name=f"-help | {len(bot.guilds)} servers"))
Beispiel #3
0
def get_prefix(bot, message):
    if not message.guild:
        return commands.when_mentioned_or("-")(bot, message)

    prefixes = read_json("prefixes")

    if str(message.guild.id) not in prefixes:
        return commands.when_mentioned_or("-")(bot, message)

    prefix = prefixes[str(message.guild.id)]
    return commands.when_mentioned_or(prefix)(bot, message)
    async def changeprefix(self, ctx, prefix):
        """Change my prefix for this server."""

        if len(prefix) > 6:
            return await ctx.send(
                "The prefix must be less than 6 characters in length."
            )

        prefixes = read_json("prefixes")
        prefixes[str(ctx.guild.id)] = prefix
        write_json(prefixes, "prefixes")

        await ctx.send(f"Prefix changed to: {prefix}")
    async def deleteprefix(self, ctx):
        """Reset my prefix for this server."""

        prefixes = read_json("prefixes")

        try:
            prefixes.pop(str(ctx.guild.id))
        except KeyError:
            return await ctx.send("This servers prefix is already `-`.")

        write_json(prefixes, "prefixes")

        await ctx.send(
            "Reverted this servers prefix back to `-`. "
            "If you ever want to change it, run `-prefix change <newprefix>`"
        )
    async def unblacklist(self, ctx, user: discord.User):
        """Unblacklist someone from using me."""

        self.bot.blacklisted.remove(
            user.id)  # Removes the blacklist from the bot list
        data = read_json("blacklist")  # Reads the json file information

        try:
            data["blacklisted"].remove(user.id)
        except ValueError:  # If they are not blacklisted then it raises an error
            return await ctx.send(
                "They are not blacklisted from me. You cant unblacklist "
                "someone that's currently not already blacklisted.")
        write_json(data, "blacklist")  # Saves the json list

        await ctx.send(f"{user.name} is no longer blacklisted from me."
                       )  # Sends the message
    async def blacklist(self, ctx, user: discord.User):
        """Blacklist someone from using me."""

        if (ctx.message.author.id == user.id
            ):  # Checks if the user is the person who invoked the command
            return await ctx.send("You can't blacklist yourself.")

        self.bot.blacklisted.append(
            user.id)  # Adds the blacklist to the bot list
        data = read_json("blacklist")  # Reads the json file information

        if str(
                user.id
        ) in data["blacklisted"]:  # Check if they are already blacklisted
            return await ctx.send("They are already blacklisted from me.")

        data["blacklisted"].append(
            user.id)  # Adds the blacklist to the json list for the future
        write_json(data, "blacklist")  # Saves the json list

        await ctx.send(f"{user.name} is now blacklisted from me."
                       )  # Sends the message
Beispiel #8
0
import os
from pathlib import Path

import discord
from discord.ext import commands

from utils.json_loader import read_json

cwd = Path(__file__).parents[0]
cwd = str(cwd)

secret_file = read_json("token")
config_file = read_json("config")


def get_prefix(bot, message):
    return commands.when_mentioned_or(bot.PREFIX)(bot, message)


bot = commands.Bot(
    command_prefix=get_prefix,
    case_insensitive=True,
    help_command=None,
    intents=discord.Intents.all(),
)
bot.config_token = secret_file["token"]

bot.PREFIX = "--"

bot.player = None
bot.server = config_file["server"]