1
votes

Okay I'm making a python Discord Bot using Discord python API. I'm trying to compare the message after they message the command ?event_add {message/event they want to add} to current list of events. If the message matches the current list of events the bot would return with a message saying that we already have the event. My problem is that the string does not want to compare with the list and always returns back that it does not match.

OS : Windows 10 Creators Update

Python : 3.6.2

Discord.py : https://discordpy.readthedocs.io/en/latest/, GitHub : https://github.com/Rapptz/discord.py

Code:

import discord
from discord.ext import commands
import logging
import sys
import time
import asyncio

bot = commands.Bot(command_prefix="/")
console = discord.Object("357208549614419970")
events = {"learn to bake"}


@bot.event
async def on_ready():
    print("Logged in as: ")
    print(bot.user.id)
    print(bot.user.name)
    print("******************")

@bot.command(pass_context = True)
async def test(ctx):
    await bot.say("Testing...... Am I a real boy yet?")
    events = ['drawn out a dragon, and do a hand stand']
    await bot.say(events)

@bot.command(pass_context = True)
async def add_event(ctx, event):
    if event in events:
        await bot.say("Sorry we already have that, also we need to teach %s 
to read. Add that to the list please." % ctx.message.author.mention)
    else:
        await bot.say("Something is broken %s" % ctx.message.author.mention)
1
Please post a concise section of code that is causing the issue, instead of just pasting your entire program.Sam Rockett

1 Answers

1
votes

It looks like you are defining events on the global scope as a set, and then trying to redifine it in test().

The events defined in test() is on a local scope, meaning it will be deleted at the end of the function call, whereas the events you are trying to use in add_event() is the one on the global scope, which has nothing to do with the one in test().

Anyway, to fix it, just add a global events to the top of test(). This will mean that when you redefine events, you will replace the already global one.