-
Notifications
You must be signed in to change notification settings - Fork 4
/
bot.py
41 lines (31 loc) · 1.43 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# listen for messages on a discord server (globally, all channels)
# send to specified phone number if the message wasn't sent from the bot
import discord
import asyncio
from twilio.rest import TwilioRestClient
# discord.py has logging available: see docs. you probs won't need.
twilioNumber = "+10005555555"
phoneNumber = "+10005555555" # to send messages to (ie, your user)
botName = 'sms-bot' # IMPORTANT! must be real bot username
# otherwise you'll get infinite loops of the bot responding to itself
twilioAccountSid = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
twilioAuthToken = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
discordBotToken = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
###############################################################################
# auth client objects
twilioClient = TwilioRestClient(twilioAccountSid, twilioAuthToken)
discordClient = discord.Client()
@discordClient.event
async def on_ready():
print('Logged in as ' + discordClient.user.name + " " + discordClient.user.id)
print('------')
@discordClient.event
async def on_message(message):
if message.author.name != botName:
twilioClient.messages.create(
to = phoneNumber,
from_ = twilioNumber,
body = "{} - {}".format(message.author.name,message.content),
)
print("sent message: {} - {}".format(message.author.name,message.content))
discordClient.run(discordBotToken)