【发布时间】:2022-01-05 17:45:09
【问题描述】:
我希望我的机器人将 DM 消息从特定 ID 转发到我的 discord 服务器中的特定频道 ID,并将来自同一特定服务器频道的消息转发回 DM 中的同一特定用户 ID。
我遇到的问题:
- 当机器人在 DM 中收到消息时,机器人会将消息发送到服务器通道 ID,然后它会发送回 DM,如果消息作者 ID 是我的机器人不转发,我想停止此循环。
- 如果机器人同时收到 2 条以上的消息,它只会转发第一条消息,我希望它转发所有消息。
import discum
import config
bot = discum.Client(token=config.token, log=False)
@bot.gateway.command
def on_message(resp):
if resp.event.ready_supplemental:
try:
user = bot.gateway.session.user
print(f"Forwarding bot started. Logged in as {user['username']}#{user['discriminator']}")
guilds = bot.gateway.session.guilds
for guild_id, guild in guilds.items():
bot.gateway.request.lazyGuild(guild_id, {1: [[0, 99]]}, typing=True, threads=False, activities=True, members=[])
except Exception as e:
return
if resp.event.message:
message = resp.parsed.auto()
if not message['content'] or not message['content'] != "":
return
try:
if str(message['channel_id']) == str(config.dm_channel_id) and str(message['author']['id']) != str(config.bot_account_user_id):
bot.sendMessage(str(config.from_dm_channel_id), message['content'].strip())
elif str(message['channel_id']) == str(config.to_dm_channel_id) and str(message['author']['id']) != str(config.user_to_dm_channel_id):
dm = bot.createDM([config.user_to_dm_channel_id]).json()["id"]
bot.sendMessage(dm, message['content'].strip())
except Exception as e:
pass
bot.gateway.run()
【问题讨论】: