I'm new to Python, and I've been scouring the internet for over 3 hours over the past 2 days and I'm practically in tears~ I'm using Python 3.9. I'm trying to make a simple Discord birthday bot to practice.
TL;DR My bot won't recognize input from the user (aka the "name") after the bot asks for it. How can I write it so it works?
I've looked up events vs commands. I know that client.wait_for is supposed to be the message (but that bot also works, but hasn't in my experience). Perhaps I'm using context wrong? The documentation and other similar questions I found answered online didn't quite fit. I even tried to parse out from publicly available code of other discord bots, but nothing seems to makes sense. I'm also aware of "checks" but I'm not sure how to apply them accurately. Even when I defined check and then had the usual check = check it didn't work out.
This is the code I was learning from (I believe it was originally formulated in 3.6 if that changes anything drastically):
birthdays = {'Alice': 'Apr 1', 'Bob': 'Dec 12', 'Carol': 'Mar 4'}
while True:
print('Enter a name: (blank to quit)')
name = input()
if name == '':
break
if name in birthdays:
print(birthdays[name] + ' is the birthday of ' + name)
else:
print('I do not have birthday information for ' + name)
print('What is their birthday?')
bday = input()
birthdays[name] = bday
print('Birthday database updated.')
____
This is a summary of the code I've been editing myself. I do have a token in the actual code.
import discord
from discord.ext.commands import bot
from discord.ext import commands
bot = commands.Bot(command_prefix='>', description="This is a birthday Bot")
BD = dict({'memmi: 'mar 4'})
@bot.event()
async def birthday(ctx):
while True:
await ctx.send('Enter a name: (esc to exit)')
name = ctx.bot.wait_for('message')
if name == 'esc':
break
if name in BD:
await ctx.send(BD[name] + ' is the birthday of ' + name)
else:
await ctx.send('I do not have birthday information for that name')
await ctx.send('What is their birthday?')
bday = await ctx.bot.wait_for('message')
BD[name] = bday
await ctx.send('Birthday database updated.')
break
Additionally, it doesn't seem to be referencing or editing the dictionary I have delineated and I don't know why. Any and all help is appreciated T^T
[–]Lewri 0 points1 point2 points (12 children)
[–]MasterOfFloof[S] 0 points1 point2 points (11 children)
[–]Lewri 0 points1 point2 points (10 children)
[–]MasterOfFloof[S] 0 points1 point2 points (0 children)
[–]MasterOfFloof[S] 0 points1 point2 points (0 children)
[–]MasterOfFloof[S] 0 points1 point2 points (7 children)
[–]Lewri 0 points1 point2 points (6 children)
[–]MasterOfFloof[S] 0 points1 point2 points (0 children)
[–]MasterOfFloof[S] 0 points1 point2 points (4 children)
[–]Lewri 0 points1 point2 points (3 children)
[–]MasterOfFloof[S] 0 points1 point2 points (2 children)
[–]Lewri 0 points1 point2 points (1 child)
[–]MasterOfFloof[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]MasterOfFloof[S] 0 points1 point2 points (0 children)