Skip to content

Instantly share code, notes, and snippets.

@Artemis21
Created June 6, 2020 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Artemis21/54e6dd41dd19fae5cef00ab340564049 to your computer and use it in GitHub Desktop.
Save Artemis21/54e6dd41dd19fae5cef00ab340564049 to your computer and use it in GitHub Desktop.
Simple cross-channel discord posting
import discord
import logging
CHANNELS = (123, 456)
TOKEN = 'TOKEN_GOES_HERE'
logging.basicConfig(level=logging.INFO)
cl = discord.Client()
async def get_wh(ch):
existing = await ch.webhooks()
if existing:
return existing[0]
return await ch.create_webhook(name='interguild')
async def forward(wh, mes):
if mes.author.bot:
return
name = mes.author.name
av = mes.author.avatar_url
text = mes.content
if not text:
return
await wh.send(content=text, username=name, avatar_url=av)
@cl.event
async def on_ready():
global ch1, ch2
ch1 = cl.get_channel(CHANNELS[0])
ch2 = cl.get_channel(CHANNELS[1])
act = discord.Activity(
name='messages.',
type=discord.ActivityType.listening
)
await cl.change_presence(activity=act)
print('Ready!')
@cl.event
async def on_message(message):
if message.author.id == cl.user.id:
return
if cl.user.id in [i.id for i in message.mentions]:
await message.channel.send(
'Hi there! I\'m a simple messenger with no commands.'
)
if message.channel.id == ch1.id:
ch = ch2
elif message.channel.id == ch2.id:
ch = ch1
else:
return await cl.process_commands(message)
wh = await get_wh(ch)
await forward(wh, message)
await cl.process_commands(message)
cl.run(TOKEN)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment