|
import discord |
|
from discord.ext import commands |
|
from slack_sdk import WebClient |
|
from slack_sdk.errors import SlackApiError |
|
|
|
DISCORD_T = |
|
SLACK_T = |
|
SLACK_CHANNEL_ID = |
|
|
|
TRIGGERS = { |
|
"urgent": "<@U12345678>", |
|
"help": "<@U87654321>", |
|
} |
|
|
|
intents = discord.Intents.all() |
|
intents.messages = True |
|
bot = commands.Bot(command_prefix='!', intents=intents) |
|
|
|
|
|
slack_client = WebClient(token=SLACK_T) |
|
|
|
@bot.event |
|
async def on_ready(): |
|
print(f'Logged in as {bot.user}') |
|
|
|
@bot.event |
|
async def on_message(message): |
|
if message.author == bot.user: |
|
return |
|
|
|
content = message.content.lower() |
|
for trigger, slack_mention in TRIGGERS.items(): |
|
if trigger in content: |
|
await post_to_slack(message.content, slack_mention) |
|
break |
|
|
|
async def post_to_slack(content, slack_mention): |
|
try: |
|
response = slack_client.chat_postMessage( |
|
channel=SLACK_CHANNEL_ID, |
|
text=f"{slack_mention} New message in Discord: {content}" |
|
) |
|
except SlackApiError as e: |
|
print(f"Error posting to Slack: {e.response['error']}") |
|
|
|
bot.run(DISCORD_T) |
|
|