【发布时间】:2020-04-20 11:02:21
【问题描述】:
需要一些帮助,试图在不和谐频道和电报频道之间架起一座桥梁。我收到了从 Discord 发送到 Telegram 的消息,但我很难将 Telegram 消息发送到 Discord。我收到了 Telegram 消息,但我不知道如何将它们传递给 Discord。
from discord.ext import commands
import telegram.ext
from telegram.ext import MessageHandler, Filters, Updater
telegram_token = 'str'
telegram_group = 'str'
discord_channel = 'int'
class repeater(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.Cog.listener()
async def on_message(self, message):
homechannel = self.bot.get_channel(discord_channel)
if message.channel == homechannel:
Tele_Bot = telegram.Bot(token=telegram_token)
Tele_Bot.sendMessage(chat_id=telegram_group, text=f'{message.guild.name}:{message.author}:\n{message.content}')
print('Message Detected from Discord & Sent')
class telegram_repeater(commands.Cog):
def __init__(self, bot):
self.bot = bot
updater = Updater(token=telegram_token, use_context=True)
dispatcher = updater.dispatcher
def echo(update, context):
#The Magic would Happen here.
echo_handler = MessageHandler(Filters.text, echo)
dispatcher.add_handler(echo_handler)
updater.start_polling()
def setup(bot):
bot.add_cog(repeater(bot))
bot.add_cog(telegram_repeater(bot))
我怎样才能获得一个不和谐频道,然后向它发送电报消息?
【问题讨论】:
-
如果您不想在处理异步同步时遇到任何大问题,请使用异步电报库。
标签: python telegram discord.py python-telegram-bot