Reputation: 45
I am a beginner in python and i am to trying to code a discord game bot in which you have to choose your paths.
I want that the user first run !adv command and then can press 'c' to continue but my code is not able to do so.
I am not getting any error but after running the !adv command ,i am not able to run the 'c' command to further do something.
client = discord.Client()
@client.event
async def on_ready():
general_channel = client.get_channel(864471185907908608)
await general_channel.send('Hey!')
@client.event
async def on_message(message):
count = 0
msg = message.content.lower()
general_channel = client.get_channel(864471185907908608)
if count == 0:
if msg == '!adv':
await general_channel.send('Hello '+ message.author.name +'. \nWelcome to the Lands of The Supreme Lord , The Godfather.\nYou woke up in the marketplace with crowd bustling everywhere.\nYou have many questions.\nWhat led you to this place and whats your destiny?\nYou are set to write your own path here.\nPress c to continue.')
count += 1
async def on_message(message):
msg = message.content.lower()
if count == 1:
if msg == 'c':
await general_channel.send('\nYou see a vase shop and an weaponsmith ahead.\nDecide who you want to talk.\nType v or w')
Please include the code for the solution as well because it is easy to understand with code.
Thanks in advance
Upvotes: 0
Views: 79
Reputation: 15728
You cannot really have more than one on_message
(though you're not registering the second one as an event). To wait for a user response you should use client.wait_for
:
@client.event
async def on_message(message):
def check(m): # simple check to wait for the correct user
return m.author == message.author and m.channel == message.channel
count = 0
msg = message.content.lower()
general_channel = client.get_channel(864471185907908608)
if count == 0:
if msg == '!adv':
await general_channel.send('Hello '+ message.author.name +'. \nWelcome to the Lands of The Supreme Lord , The Godfather.\nYou woke up in the marketplace with crowd bustling everywhere.\nYou have many questions.\nWhat led you to this place and whats your destiny?\nYou are set to write your own path here.\nPress c to continue.')
# Waiting for the response
resp = await client.wait_for("message", check=check)
if resp.content.lower() == "c":
# continue the story
await general_channel.send('\nYou see a vase shop and an weaponsmith ahead.\nDecide who you want to talk.\nType v or w')
resp2 = await client.wait_for("message", check=check)
if resp2.content.lower() in ["v", "w"]:
# continue the story
...
count += 1
You might wanna use some return
statements to not have such deep indentation.
Upvotes: 2