-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathfirstmessage.py
50 lines (39 loc) · 1.59 KB
/
firstmessage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import logging
import discord
from redbot.core import Config, commands
from redbot.core.bot import Red
log = logging.getLogger("red.fox_v3.firstmessage")
class FirstMessage(commands.Cog):
"""
Provides a link to the first message in the provided channel
"""
def __init__(self, bot: Red):
super().__init__()
self.bot = bot
self.config = Config.get_conf(
self, identifier=701051141151167710111511597103101, force_registration=True
)
default_guild = {}
self.config.register_guild(**default_guild)
async def red_delete_data_for_user(self, **kwargs):
"""Nothing to delete"""
return
@commands.command()
async def firstmessage(self, ctx: commands.Context, channel: discord.TextChannel = None):
"""
Provide a link to the first message in current or provided channel.
"""
if channel is None:
channel = ctx.channel
try:
message: discord.Message = next(
iter([message async for message in channel.history(limit=1, oldest_first=True)]),
None,
)
except (discord.Forbidden, discord.HTTPException):
log.exception(f"Unable to read message history for {channel.id=}")
await ctx.maybe_send_embed("Unable to read message history for that channel")
return
em = discord.Embed(description=f"[First Message in {channel.mention}]({message.jump_url})")
em.set_author(name=message.author.display_name, icon_url=message.author.avatar.url)
await ctx.send(embed=em)