33 lines
No EOL
1.2 KiB
Python
33 lines
No EOL
1.2 KiB
Python
from redbot.core import commands
|
|
from discord.ext.commands import Cog
|
|
from redbot.core.bot import Red
|
|
import discord
|
|
|
|
|
|
class SilentMode(commands.Cog):
|
|
"""Makes the bot use @silent for every message it sends."""
|
|
|
|
def __init__(self, bot: Red):
|
|
self.bot = bot
|
|
self.original_send = discord.abc.Messageable.send
|
|
discord.abc.Messageable.send = self._silent_send
|
|
|
|
def cog_unload(self):
|
|
"""Restore the original send method when the cog is unloaded."""
|
|
discord.abc.Messageable.send = self.original_send
|
|
|
|
async def _silent_send(self, *args, **kwargs):
|
|
"""Override the send method to add @silent to every message."""
|
|
if args and isinstance(args[0], str):
|
|
args = ("@silent " + args[0],) + args[1:]
|
|
elif "content" in kwargs and kwargs["content"]:
|
|
kwargs["content"] = "@silent " + kwargs["content"]
|
|
elif not kwargs.get("content") and (kwargs.get("embed") or kwargs.get("file")):
|
|
kwargs["content"] = "@silent"
|
|
|
|
return await self.original_send(self, *args, **kwargs)
|
|
|
|
|
|
async def setup(bot: Red):
|
|
"""Add the cog to the bot."""
|
|
await bot.add_cog(SilentMode(bot)) |