Reputation: 54
I have a bot that queues you into a party finder. When the number of queues reaches 2, it resets to 0. I have 2 commands, one for the first person, another for the second to record their names. However, when I get it to 2, it goes to queue = 0 and also fires the command when queue = 0, making it fire twice.
How can I fix this?
import discord
import os
from discord.utils import get
from discord.ext import commands
@client.event
async def on_message(message): #Defines Message
#If You Queue, And Role Requirement to Do So
if message.content.startswith('-queue duos'):
global queue
if queue == 1:
role = discord.utils.get(message.guild.roles, id=830557149863608367)
if role in message.author.roles:
print('you have queued')
global author2
author2 = message.author
print(author2)
#Adds Role Duos
role = discord.utils.get(message.guild.roles, id=830219965549510656)
await message.author.add_roles(role)
#Removes Role NoQueue
role4 = discord.utils.get(message.guild.roles, id=830557149863608367)
await message.author.remove_roles(role4)
#Gives Message
await message.channel.send('you have joined the duos queue sit tight!')
queue += 1
await message.channel.send(queue)
if queue == 2:
queue = 0
print('SUCCESS')
if queue == 0:
role = discord.utils.get(message.guild.roles, id=830557149863608367)
if role in message.author.roles:
print('you have queued')
global author
author = message.author
print(author)
#Adds Role Duos
role = discord.utils.get(message.guild.roles, id=830219965549510656)
await message.author.add_roles(role)
#Removes Role NoQueue
role4 = discord.utils.get(message.guild.roles, id=830557149863608367)
await message.author.remove_roles(role4)
#Gives Message
await message.channel.send('you have joined the duos queue sit tight!')
queue += 1
await message.channel.send(queue)
#Is They Already Queued and Have Duos Role
else:
await message.channel.send('You Already Queued!')
Upvotes: 1
Views: 82
Reputation: 451
You are changing the queue
variable and then checking it, which will result in it executing twice, a simple way to fix this is to only use if
on the first check on the queue, and use elif
on the others, IE:
queue = 1
if queue == 1:
#Do Something
queue = 0
elif queue == 0:
#Do Something else
queue = 2
elif queue == 2:
#Do Something else
queue = 1
The example code above only executes the first if
statement, since elif
is only executed if the if
statement it is linked to was not executed.
Upvotes: 2