2
import random

import asyncio

import aiohttp

import json
from discord import Game
from discord.ext.commands import Bot


import discord

TOKEN = 'Token'

 client = discord.Client()

botnum = 0
 @client.event
 async def on_message(message):
# we do not want the bot to reply to itself
if message.author == client.user:
    return

if message.content.startswith('PeriBot'):
    msg = "I'm Busy! D:<".format(message)
    await client.send_message(message.channel, msg)
if  discord.message and botnum == 20
    msg = "You Clods are so loud!".format(message)
    await client.send_message(message.channel, msg)
    set botnum == 0
else:
    botnum + 1
 @client.event
async def on_ready():
print('Online and Ready to Play!')
print(client.user.name)
print(client.user.id)
await client.change_presence(game=discord.Game(name="With Emotions")) 
 print('------')

 client.run("Token")

I want it to say a message every 20 messages but I am unsure how. I have somthing named botnum and it is == 0 and if there isn't 20 botnum's then it adds 1 to the botnum. If there is 20 it says a msg. I want it to add 1 to botnum every msg.

  • You can assign a value to a variable using an assignment statement, such as `botnum = 0`, or `botnum = botnum + 1`. If you're thinking "yes, I tried that, but then when I tried to access the value of botnum in another function, it crashed, or it just gave me the original unmodified value", it may be useful to research the concept of global variables. – Kevin Aug 07 '18 at 14:18
  • `if discord.message` <- There is no `discord.message`, so your code is likely not getting to this point. There is a `discord.Message`, but that's a class, and will always be truthy. What exactly is this supposed to check? – Patrick Haugh Aug 07 '18 at 14:33

1 Answers1

1

I'm noticing a lot of syntax errors in your code, I've updated it below with what it should look like, and noted the changes with ### at the end of the line where it was modified. As for "make them notice every message" I'll need some clarification and then update my answer if this doesn't suit your needs. I think the code I just provided should update the botnum with 1 every time a message is sent that isn't PeriBot which should solve your problem.

import random    
import asyncio    
import aiohttp
import discord
import json
from discord import Game
from discord.ext.commands import Bot        

TOKEN = 'Token'

client = discord.Client()

@client.event
async def on_ready():
    print('Online and Ready to Play!')
    print(client.user.name)
    print(client.user.id)
    await client.change_presence(game=discord.Game(name="With Emotions")) 
    print('------')

botnum = 0
@client.event
async def on_message(message):
# we do not want the bot to reply to itself
    if message.author == client.user:
        return    
    elif message.content.startswith('PeriBot'): ### Updated to elif which is more acceptable
        msg = "I'm Busy! D:<".format(message)
        await client.send_message(message.channel, msg)
    elif  discord.message and botnum == 20: ### forgot a ":" and Updated to elif which is more acceptable
        msg = "You Clods are so loud!".format(message)
        await client.send_message(message.channel, msg)
        botnum = 0 ### you were comparing and not setting botnum to 0
    else:
        botnum += 1 ### This will add 1 to the preexisting number of botnum

client.run("Token")
J0hn
  • 570
  • 4
  • 19
  • Thanks, but when I try to run it with python the python cmd prompt thing crashes/closes. Also the bot doesn't come online :/ . Also for the message thing I want it to add botnum every time someone sends a message – Electron Group Aug 07 '18 at 15:20
  • @ElectronGroup Here's a discord bot I created: https://github.com/Sp4zzy/Jbot-for-Discord It's a bit garbled and I'm working on a code rewrite but you might be able to get something out of it by reading it over. Also, for debugging the crashing, I recommend launching the bot using IDLE, that way when it crashes you can read the error message. If you can give me a specific error (by running with IDLE) I can help you with what you need to change after / during my lunch break. – J0hn Aug 07 '18 at 15:24
  • I honestly don't know what IDLE is or how to start it. Also my computer is acting up so I have to restart it and restarting will take a while so It will be a while before I can get back to you – Electron Group Aug 07 '18 at 15:47
  • IDLE is the default IDE for python coding. You should be able to download it for your specific python version on the python website. My discord bot uses 3.6.5 and I've had some strange issues with 3.7.0. I highly recommend using it if you're new to python. – J0hn Aug 07 '18 at 15:50
  • When I run it through IDLE it says "Syntax Error: Multiple statements found while compiling a single statement" – Electron Group Aug 07 '18 at 17:37
  • @ElectronGroup That's a strange one, I found this: https://stackoverflow.com/questions/21226808/syntaxerror-multiple-statements-found-while-compiling-a-single-statement but I can't see where in your code that would apply (assuming you've done my changes). Do me a favor and try to run my EXACT code after replacing the TOKEN = with your token for your bot. I rearranged some stuff so that it matches how I have mine laid out (which works) and hopefully that will get rid of your error. That Error sounds like a syntax issue. – J0hn Aug 07 '18 at 18:33
  • Okay so I get the same error but when I run it with regular python the command prompt thing doesn't crash but she doesn't say anything after 20msgs are sent – Electron Group Aug 07 '18 at 18:42
  • So I looked back at my Peribot command prompt and I got alot of errors https://pastebin.com/CfeUdXXR this shows what it said – Electron Group Aug 07 '18 at 19:54
  • @ElectronGroup I'll have to check this when I get home in ~2 hours – J0hn Aug 07 '18 at 20:08
  • @ElectronGroup All those errors are related to `botnum` being referenced before assignment. For some reason `botnum` is outside of the scope of the rest of the program for you. Make sure you're declaring `botnum` above the `on_message` function, and check for typos and proper tab spacing. – J0hn Aug 07 '18 at 21:47
  • Um, I am unsure what you mean? Is botnum = 0 not declairing botnum? I am unsure – Electron Group Aug 07 '18 at 21:59