I want my bot to forward DM messages from specific ID to a specific channel id in my discord server and to forward messages from the same specific server channel back to the same specific user id in DM.
Issues I have:
- When the bot receive a message in DM the bot sends the message to the server channel id then it sends back to DM and I want to stop this loop, if message author id its my bot to not forward it.
- If the bot receive 2+ messages at the same time it only forwards the first one and I want it to forward all of them.
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()