コード例 #1
0
ファイル: help_command.py プロジェクト: tazz4843/DHV4
    def setup(cls, bot: MyBot):
        cog = cls(bot)
        bot.add_cog(cog)
        bot.logger.debug("Replacing previous help command...")
        cog.old_help_command = bot.help_command
        bot.help_command = ButtonsHelpCommand()
        bot.logger.debug("Help command replaced...")

        return cog
コード例 #2
0
async def submit_error_message(exc: BaseException, doing: str, bot: MyBot, ctx: Optional[MyContext] = None):
    if bot is None:
        return  # unknown bug!
    error_channel = bot.get_channel(796093696374079519)
    if ctx:
        desc = f"Guild details:\n" \
               f"ID: `{ctx.guild.id}`\n" \
               f"Name: `{ctx.guild.name}`\n\n" \
               f"Channel details:\n" \
               f"ID: `{ctx.channel.id}`\n" \
               f"Name: `{ctx.channel.name}`\n\n" \
               f"Invoking message details:\n" \
               f"ID: `{ctx.message.id}`\n\n" \
               f"Author details:\n" \
               f"ID: `{ctx.author.id}`\n" \
               f"Name: `{str(ctx.author)}`"
        sentry_sdk.set_context("user", {"repr": repr(ctx.author), "id": ctx.author.id,
                                        "name": str(ctx.author)})
        sentry_sdk.set_context("channel", {"repr": repr(ctx.channel), "id": ctx.channel.id})
        sentry_sdk.set_context("guild", {"repr": repr(ctx.guild), "id": ctx.guild.id})
        sentry_sdk.set_context("message", {"repr": repr(ctx.message), "id": ctx.message.id})
        sentry_sdk.set_context("command", {"repr": repr(ctx.command)})
    else:
        desc = "No context was passed, possibly a slash command?"
    error_embed = discord.Embed(title=f"Fatal error while working on {doing}!",
                                description=desc, color=discord.Color.dark_red())
    tb = f"```py\n{''.join(traceback.format_tb(exc.__traceback__))}\n```"
    error_embed.add_field(name="Exception Name", value=str(exc.__class__))
    error_embed.add_field(name="Exception Reason", value=str(exc), inline=False)
    kwargs = {}
    if len(tb) < 1024:
        error_embed.add_field(name="Exception Traceback", value=tb)
    else:
        error_embed.add_field(name="Exception Traceback", value="Attached File")
        kwargs["file"] = discord.File(StringIO(''.join(traceback.format_tb(exc.__traceback__))),
                                      filename="traceback.txt")
    kwargs["embed"] = error_embed
    try:
        sentry_sdk.capture_exception(exc)
    except Exception as e:
        bot.logger.exception("Error while sending exception to Sentry!", exc_info=e)
    await error_channel.send(**kwargs)
コード例 #3
0
intents.emojis = False
intents.integrations = False
intents.webhooks = False
intents.invites = False
intents.voice_states = False
intents.typing = False

# https://discordpy.readthedocs.io/en/latest/api.html#discord.AllowedMentions
allowed_mentions = discord.AllowedMentions(
    everyone=False,
    roles=False,
    users=True,
)

bot = MyBot(description=config["bot"]["description"],
            intents=intents,
            allowed_mentions=allowed_mentions,
            help_command=EmbedHelpCommand())

for cog_name in config["cogs"]["cogs_to_load"]:
    try:
        bot.load_extension(cog_name)
        bot.logger.debug(f"> {cog_name} loaded!")
    except Exception as e:
        bot.logger.exception('> Failed to load extension {}\n{}: {}'.format(
            cog_name,
            type(e).__name__, e))

# thanks Silmät!
try:
    import uvloop
except (ImportError, ModuleNotFoundError):
コード例 #4
0
 def setup(cls, bot: MyBot):
     return bot.add_cog(cls(bot))
コード例 #5
0
import asyncio
import uvloop

from utils.config import load_config
from utils.bot_class import MyBot

asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())

config = load_config()

bot = MyBot(description=config["bot"]["description"])

for cog_name in config["cogs"]["cogs_to_load"]:
    try:
        bot.load_extension(cog_name)
        bot.logger.debug(f"> {cog_name} loaded!")
    except Exception as e:
        bot.logger.exception('> Failed to load extension {}\n{}: {}'.format(
            cog_name,
            type(e).__name__, e))

bot.run(config['auth']['discord']['token'])
コード例 #6
0
ファイル: main.py プロジェクト: paris-ci/TSPDiscord
intents.members = True  # Privileged
intents.bans = True
intents.emojis = True
intents.integrations = True
intents.webhooks = True
intents.invites = True
intents.voice_states = True
intents.typing = False

# https://discordpy.readthedocs.io/en/latest/api.html#discord.AllowedMentions
allowed_mentions = discord.AllowedMentions(
    everyone=False,
    roles=False,
    users=True,
)

bot = MyBot(description=config["bot"]["description"],
            intents=intents,
            allowed_mentions=allowed_mentions)

for cog_name in config["cogs"]["cogs_to_load"]:
    try:
        bot.load_extension(cog_name)
        bot.logger.debug(f"> {cog_name} loaded!")
    except Exception as e:
        bot.logger.exception('> Failed to load extension {}\n{}: {}'.format(
            cog_name,
            type(e).__name__, e))

bot.run(config['auth']['discord']['token'])
コード例 #7
0
 def setup(cls, bot: MyBot):
     bot.help_command = BoatHelp()
     return super().setup(bot)
コード例 #8
0
ファイル: main.py プロジェクト: kai2342340gamer/covid-bot-v5
    bf_config = config["auth"]["blackfire"]
    probe.initialize(**bf_config)
    probe.enable()

sentry_sdk.init(config["auth"]["sentry"]["sentry_url"], traces_sample_rate=1.0)

if config['database']['enable']:
    asyncio.ensure_future(init_db_connection(config['database']))

basic_intents = discord.Intents.none()
basic_intents.guilds = True
basic_intents.webhooks = True
basic_intents.messages = True
basic_intents.reactions = True
bot = MyBot(
    description=config["bot"]["description"],
    intents=basic_intents,
    member_cache_flags=discord.MemberCacheFlags.from_intents(basic_intents))

bot.help_command = BoatHelp()
bot.blackfire = blackfire

stcd = statcord.Client(bot, config["auth"]["statcord"]["token"])
stcd.start_loop()
bot.statcord = stcd  # best way i know of to make a global system

for cog_name in config["cogs"]["cog_reloader"]["cogs_to_load"]:
    try:
        bot.load_extension(cog_name)
        bot.logger.debug(f"{cog_name} loaded!")
    except Exception as e:
        bot.logger.exception(