Reputation: 111
So I want to have a system, where when a certain action occurs on the website, to open a support ticket on the discord server automatically. I can use any discord ticket bot that would work. I tried to use webhooks with php and try to get a bot to send the command to open a ticket but I found out that discord bots can't run other discord bot commands. What should my plan of action be?
Right now I'm using this ticket bot that runs off node.js and uses discord.js
Any suggestions are appreciated.
Upvotes: 2
Views: 3489
Reputation: 37
I have a proposal but is implemented in python
from server import app
from bot import bot
from dotenv import load_dotenv
import os
import multiprocessing
from gevent.pywsgi import WSGIServer
env_path = os.path.dirname(__file__) + "/.env"
load_dotenv(env_path)
def start_server():
app.run()
def start_bot():
token = os.getenv("BOT_TOKEN")
bot.run(token)
def start_multiprocess():
bot_thread = multiprocessing.Process(name="bot_thread", target=start_bot)
server_thread = multiprocessing.Process(name="server_thread", target=start_server)
bot_thread.start()
server_thread.start()
def run():
start_multiprocess()
if __name__ == "__main__":
run()
Assume that app is just your average Flask app and bot your regular instance of commands.Bot
.
If you run this will work (a web server and discord but running as expected independently) but have certain flaws such as the process cannot communicate with each other, in other words, you cannot use functions or variables of the bot from the server. To address those limitations you will have to look further into the concurrency packages of python such as asyincio
Upvotes: 0
Reputation: 957
This is a little vague so I'll try my best to answer it.
Run an express server in the same app as your Discord Bot that listens for you to POST a Ticket. You can learn more about express here: https://expressjs.com/en/starter/installing.html
const { Client } = require('discord.js');
const client = new Client();
// Your discord.js BOT code.
const express = require('express');
app.use(express.bodyParser());
app.post('/ticket', async (request, response) => {
// console.log(request.body); // the information in your POST request's body
const guild = await client.guilds.fetch('guild_id');
guild.channels.create(request.body.ticketName);
});
app.listen(3000);
This was a quick mockup and can be implemented in many ways, once you learn express you can find a way that fits your needs.
Unless the bot has an API or allows bots to use its commands, you CANNOT do this without the use of a self-bot. (Not recommended: https://support.discord.com/hc/en-us/articles/115002192352-Automated-user-accounts-self-bots-)
Upvotes: 3