Skip to content

Commit

Permalink
处理消息开发
Browse files Browse the repository at this point in the history
  • Loading branch information
hongyouqin committed May 30, 2024
1 parent 37e2124 commit f3b27be
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion midjourney-bot/my_discord/channel_listen.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@

intents = Intents.default()
intents.message_content = True
intents.messages = True
bot = commands.Bot(command_prefix="", intents=intents)


@bot.event
async def on_read():
async def on_ready():
logger.debug(f"Logged in as {bot.user} (ID: {bot.user.id})")
pass


@bot.event
async def on_message(message: Message):
if message.author == bot.user:
logger.debug(f"on_message owner: {bot.user}")
return
logger.debug(f"on_message content: {message.content}")
pass

Expand Down
15 changes: 15 additions & 0 deletions midjourney-bot/my_discord/msg_handle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from typing import Union
import re

PROMPT_PREFIX = "<#"
PROMPT_SUFFIX = "#>"

USER_ID_PATTERN = f"{PROMPT_PREFIX}(\w+?){PROMPT_SUFFIX}" # 用户ID正则表达式


def match_user_id(content: str) -> Union[str, None]:
match = re.findall(USER_ID_PATTERN, content)
if match[0] is not None:
return match[0]
else:
return None

0 comments on commit f3b27be

Please sign in to comment.