0

I'm running into difficulty getting a python based discord bot to run on my apache2 webserver. I'm using the discord.py api wrapper and I installed python 3.5.1 using pyenv.

Here is my code

#!/usr/bin/env python

import discord
import asyncio

import requests.packages.urllib3
requests.packages.urllib3.disable_warnings()

client = discord.Client()

@client.event
async def on_message(message):
    if message.content.startswith('!logi'):

        Cmd = message.content.lstrip('!logi ')
        Cmd = Cmd.split()
        From = Cmd[0]
        To = Cmd[2]

        await client.send_message(message.channel, 'starting search for %s to %s' % (From, To))

        To_High=['Hydrogen Fuel','Consumer Technology','Clothing','Domestic Appliances','Animal Meat','Coffee','Fish','Fruit','Grain','Tea','Synthetic Meat','Food Cartridges','Superconductors','Heliostatic Furnaces','Basic Medicines','Paladium','Silver','Gold','Indium','Lithium','Tantalum','Titanium','Uranium','Gallium','Lepidolite','Cobalt','Computer Components','Non-Lethal Weapons']
        From_High=['Pesticides','Agricultural Medicines','Consumer Technology','Synthetic Meat','Progenitor Cells','Advanced Catalysers','Animal Monitors','Awuaponic Systems','Auto Fabricators','Bio Reducing Lichen','H.E. Suits','Resonating Separators','Robotics','Terrain Enrichment Systems','Non-Lethal Weapons','Biowaste','Scrap']

        To_Industrial=['Hydrogen Fuel','Consumer Technology','Clothing','Domestic Appliances','Animal Meat','Coffee','Fish','Fruit','Grain','Tea','Synthetic Meat','Food Cartridges','Algae','Polymers','Semiconductors','Superconductors','Basic Medicines','Progenitor Cells','Gold','Copper','Aluminium','Beryllium','Indium','Lithium','Tantalum','Titanium','Uranium','Gallium','Auto Fabricators','H.E. Suits','Robotics','Leather','Natural Fabrics','Synthetic Fabrics','Non-Lehal Weapons']
        From_Industrial=['Clothing','Domestic Appliances','Food Cartridges','Marine Supplies','Crop Harvesters','Mineral Extractors','Heliostatic Furnaces','Basic Medicines','Computer Components','Biowaste','Scrap']

        To_Agri=['Pesticides','Agricultural Medicines','Hydrogen Fuel','Consumer Technology','Clothing','Domestic Appliances','Animal Meat','Coffee','Fish','Fruit','Grain','Tea','Marine Supplies','Crop Harvesters','Basic Medicines','Progenitor Cells','Animal Monitors','Aquaponic Systems','Terrain Enrichment Systems','Non-Lethal Weapons']
        From_Agri=['Mineral Oil','Animal Meat','Coffee','Fish','Fruit','Grain','Tea','Algae','Leather','Natural Fabrics','Biowaste']

        To_Refinery=['Hydrogen Fuel','Mineral Oil','Consumer Technology','Clothing','Domestic Appliances','Animal Meat','Coffee','Fish','Fruit','Grain','Tea','Synthetic Meat','Food Cartridges','Heliostatic Furnaces','Basic Medicines','Progenitor Cells','Gallite','Indite','Uranimite','Bertrandite','Coltan','Rutile','Advanced Catalysers','Resonating Separators','Non-Lethal Weapons','Scrap']
        From_Refinery=['Hydrogen Fuel','Explosives','Polymers','Semiconductors','Superconductors','Copper','Aluminium','Beryllium','Indium','Lithium','Tantalum','Titanium','Uranium','Gallium','Lepidolite','Cobalt','Synthetic Fabrics','Biowaste']

        To_Extraction=['Hydrogen Fuel','Explosives','Consumer Technology','Clothing','Domestic Appliances','Animal Meat','Coffee','Fish','Fruit','Grain','Tea','Synthetic Meat','Food Cartridges','Mineral Extractors','Basic Medicines','Bio Reducing Lichen','H.E. Suits','Non-Letha; Weapons']
        From_Extraction=['Paladium','Silver','Gold','Gallite','Indite','Uranimite','Bertrandite','Coltan','Rutile','Biowaste']





        if From == 'High-Tech':
            Cmp1 = From_High
        if From == 'Industrial':
            Cmp1 = From_Industrial
        if From == 'Agricultural':
            Cmp1 = From_Agri
        if From == 'Refinery':
            Cmp1 = From_Refinery
        if From == 'Extraction':
            Cmp1 = From_Extraction

        if To == 'High-Tech':
            Cmp2 = To_High
        if To == 'Industrial':
            Cmp2 = To_Industrial
        if To == 'Agricultural':
            Cmp2 = To_Agri
        if To == 'Refinery':
            Cmp2 = To_Refinery
        if To == 'Extraction':
            Cmp2 = To_Extraction


        for x in range(len(Cmp1)):
            for y in range(len(Cmp2)):
                if Cmp1[x] == Cmp2[y]:
                    await client.send_message(message.channel, Cmp1[x])

        await client.send_message(message.channel, 'search finished')


    if message.content.startswith('!fact'):
        print ('received command')
        await client.send_message(message.channel, 'Welcome to Factual-Bot v0.1.0! For all your trading needs!')
        await client.send_message(message.channel, 'Use the !logi command to find profitable trade routes')
        await client.send_message(message.channel, 'The syntax is !logi [economy1] to [economy2]')
        await client.send_message(message.channel, 'The following economies are supported')
        await client.send_message(message.channel, 'High-Tech')
        await client.send_message(message.channel, 'Industrial')
        await client.send_message(message.channel, 'Agricultural')
        await client.send_message(message.channel, 'Refinery')
        await client.send_message(message.channel, 'Extraction')
        print ('transmission sent')


client.run('MTgyODU3ODMyOTM5NTIwMDAz.Ch9bIA.sse2NajDnizDGVxK6BqNIpPg_ng')

It runs perfectly fine when I run it with

python factual-bot.py

but it takes up the shell. I have gotten my webserver to run other python scripts by setting the appropriate "cgi-bin" script extensions and I make all of my scripts 755 in permissions. Nevertheless here is the error apache2 throws up

[Fri May 20 00:15:37 2016] [error] [client 192.168.0.4] Premature end of script headers: factual-bot.py
  File "/usr/lib/cgi-bin/factual-bot.py", line 12
    async def on_message(message):
        ^
SyntaxError: invalid syntax
[Fri May 20 00:15:39 2016] [error] [client 192.168.0.4] Premature end of script headers: factual-bot.py
0

I did some more research and it would seem that screen would be more suitable for my purposes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.