Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import discord
- from redbot.core import commands
- from redbot.core.i18n import Translator, cog_i18n
- from redbot.core.utils.menus import menu, DEFAULT_CONTROLS
- from redbot.core.utils.chat_formatting import escape, italics, pagify
- class Csswelcome:
- """My custom cog"""
- def __init__(self, bot):
- self.bot = bot
- # callable functions
- async def welcome(self, channel = None, member = None):
- """
- Helper function to handle the welcoming of a user
- """
- # We don't want to do anything if we don't have a channel or a member
- if channel is None or member is None:
- return
- channel_serverGuidelines_id = 482361843588005940
- channel_roles_id = 482361038478508034
- await channel.send(f"Welcome {member.mention}! Please take a moment to go over the <#{channel_serverGuidelines_id}> and let us know in <#{channel_roles_id}> which classes you are in.")
- async def pastGreet(self, ctx = None):
- """
- Greets members that joined the server while the bot was unavailable
- """
- channel_newMembers_id = 484378858968055814
- channel_newMembers = self.bot.get_channel(channel_newMembers_id)
- recentlyJoinedMembers = []
- messageLimit = 50
- # scan through the `messageLimit` most recent messages, add any new member announcment to the list of
- # `recentlyJoinedMembers` exit as soon as there is message from the bot found
- async for message in channel_newMembers.history(limit=messageLimit):
- if not message.author.bot:
- recentlyJoinedMembers.append(message)
- else:
- break
- if len(recentlyJoinedMembers) is 0:
- self.log.send("No new members found since I was last online.")
- for member in recentlyJoinedMembers:
- await self.welcome(channel_newMembers, member.author)
- # user commands
- @commands.command(name="greet", aliases=['hi'])
- async def greet(self, ctx, user: discord.Member = None):
- """
- Welcomes a user to the server
- """
- chlServerGuidelines = "<#482361843588005940>"
- chlRoles = "<#482361038478508034>"
- if user is None:
- user = ctx.author
- await self.welcome(ctx, user)
- @commands.command()
- async def roles(self, ctx, user: discord.Member = None):
- """
- Shows the roles the user has
- Defaults to author
- """
- if user == None:
- user = ctx.author
- roles = user.roles
- roleStr = ""
- for role in roles:
- if role.name != "@everyone":
- roleStr += '\n' + role.name
- await ctx.send(f"User: **{user.display_name}** has the following roles: \n{roleStr}")
- #custom events
- async def is_loaded(self):
- """
- Announces that the bot is loaded
- """
- channel_logging_id = 485218362272645120
- channel_logging = self.bot.get_channel(channel_logging_id)
- await channel_logging.send(f"Bot is loaded and ready.")
- await self.pastGreet()
- #event triggers
- async def on_member_join(self, member):
- """
- Welcome's a new user to the server
- """
- chlServerGuidelines = "<#482361843588005940>"
- chlRoles = "<#482361038478508034>"
- channel = self.bot.get_channel(484378858968055814)
- await channel.send(f"Welcome {member.mention}! Please take a moment to go over the {chlServerGuidelines} and let us know in {chlRoles} which classes you are in.")
- async def on_message(self, message):
- """
- Gets and parses a user message for what classes they are in
- """
- #channel ids
- channel_roles_id = 482361038478508034
- if message.author.bot or not message.channel.id == channel_roles_id:
- return
- channel_logging_id = 485218362272645120
- channel_logging = self.bot.get_channel(channel_logging_id)
- await channel_logging.send(f"**{message.author.display_name}** (#{message.channel}) said: *\"{message.content}\"*")
- #create channel
- #guild.create_category_channel, I thinlk?
- #@commands.command()
- #async def multi(self, ctx, *, args):
- # argslist = args.split()
- # await ctx.send("-".join(argslist))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement