You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Fox-V3/leaver/leaver.py

53 lines
1.7 KiB

7 years ago
import discord
from redbot.core import Config, checks, commands
from redbot.core.bot import Red
from redbot.core.commands import Cog, Context
7 years ago
class Leaver(Cog):
"""
Creates a goodbye message when people leave
"""
7 years ago
def __init__(self, bot: Red):
7 years ago
self.bot = bot
self.config = Config.get_conf(self, identifier=9811198108111121, force_registration=True)
6 years ago
default_guild = {"channel": ""}
7 years ago
self.config.register_guild(**default_guild)
7 years ago
6 years ago
@commands.group(aliases=["setleaver"])
7 years ago
@checks.mod_or_permissions(administrator=True)
async def leaverset(self, ctx):
"""Adjust leaver settings"""
if ctx.invoked_subcommand is None:
7 years ago
pass
7 years ago
@leaverset.command()
async def channel(self, ctx: Context):
"""Choose the channel to send leave messages to"""
guild = ctx.guild
await self.config.guild(guild).channel.set(ctx.channel.id)
await ctx.send("Channel set to " + ctx.channel.name)
7 years ago
@commands.Cog.listener()
async def on_member_remove(self, member: discord.Member):
guild = member.guild
channel = await self.config.guild(guild).channel()
7 years ago
6 years ago
if channel != "":
channel = guild.get_channel(channel)
out = "{}{} has left the server".format(
member, member.nick if member.nick is not None else ""
)
if await self.bot.embed_requested(channel, member):
await channel.send(
embed=discord.Embed(
description=out, color=(await self.bot.get_embed_color(channel))
)
)
else:
await channel.send(out)
7 years ago
else:
pass