-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathcustom_msg.py
More file actions
72 lines (59 loc) · 2.88 KB
/
custom_msg.py
File metadata and controls
72 lines (59 loc) · 2.88 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import asyncio
from typing import Optional
import discord
from redbot.core import checks, commands
from .interactive_session import InteractiveSession, SessionCancelled, make_session
class CustomMsgCog(commands.Cog):
@checks.mod()
@commands.guild_only()
@commands.group(name="msg")
async def msg_cmd(self, ctx: commands.Context):
pass
@msg_cmd.command(name="create", aliases=["send"]) # type: ignore
async def msg_create(self, ctx: commands.GuildContext, specified_channel: Optional[discord.TextChannel] = None):
channel = ctx.channel
if specified_channel is not None:
channel = specified_channel
try:
payload = await make_session(ctx)
except asyncio.TimeoutError:
return await ctx.send("Took too long to respond - exiting...")
except SessionCancelled:
return await ctx.send("Exiting...")
if payload["embed"] is None:
message = await channel.send(content=payload["content"])
else:
message = await channel.send(content=payload["content"], embed=payload["embed"])
await ctx.send(
"Message sent. "
+ "For future reference, the message is here: "
+ f"https://discord.com/channels/{ctx.guild.id}/{message.channel.id}/{message.id} (ID: {message.id})"
)
@msg_cmd.command(name="edit") # type: ignore
async def msg_edit(self, ctx: commands.Context, message: discord.Message):
"""Edit a message sent by this cog
It's best to use a message link when specifying which message to edit.
Providing a message ID is likely to fail for older messages, as they won't be in cache.
"""
if message.author != ctx.me:
return await ctx.send("You must specify a message that was sent by the bot.")
try:
payload = await make_session(ctx)
except asyncio.TimeoutError:
return await ctx.send("Took too long to respond - exiting...")
except SessionCancelled:
return await ctx.send("Exiting...")
if not payload.get("content") and message.content:
if not await InteractiveSession(ctx).get_boolean_answer(
"The original message has message content, but you have not specified any. "
+ "Would you like to keep the original content?"
):
payload.update({"content": ""})
if not payload.get("embed") and message.embeds:
if not await InteractiveSession(ctx).get_boolean_answer(
"The original message has an embed, but you have not specified one. "
+ "Would you like to keep the original embed?"
):
payload.update({"embed": None})
await message.edit(**payload)
await ctx.send("Message edited.")