User input that refers to a string array that contains numbers in discord.py
Question:
I am currently learning discord.py and the making of discord bots. So i am working on a feature that spams a text or whatever. To do so i ask the user who he wants to spam, and how many times. And it’s for this last one that i need help.
I tried to form an array in range, going from 1 to 30, and converting it to a string variable. It actually works, but the problem is when i try to collect user’s input
code below
import *
num = []
for i in range(1,31):
i+1
num.append(i)
NUMBERS_SPAM = [str(x) for x in num]
del num
print(NUMBERS_SPAM)
@client.event
async def on_message(message):
def check(m):
for number in NUMBERS_SPAM:
return m.content == number and m.channel.send == message.channel.send
msg1 = await client.wait_for("message", check=check)
await message.channel.send("let's spam")
I thought it would work, but actually the bot only answers when i enter 1, although i want it to answer when he reads an int from 1 to 30
Thanks a lot to anyone who would be helping me out !!
Answers:
So you want to prompt a user to spam x (user) y amount of times, keep it simple.
@client.command()
async def spam(ctx, user : discord.User, amount = 1):
await ctx.reply("Spamming {} {} times.".format(user,amount))
for i in range(amount): await user.send(i)
return
exits on first loop when number
is 1
– so it check only one value.
You should use if ... in ...
instead of for ... in ...
and ==
def check(m):
return (m.content in NUMBERS_SPAM) and (m.channel.send == message.channel.send)
I am currently learning discord.py and the making of discord bots. So i am working on a feature that spams a text or whatever. To do so i ask the user who he wants to spam, and how many times. And it’s for this last one that i need help.
I tried to form an array in range, going from 1 to 30, and converting it to a string variable. It actually works, but the problem is when i try to collect user’s input
code below
import *
num = []
for i in range(1,31):
i+1
num.append(i)
NUMBERS_SPAM = [str(x) for x in num]
del num
print(NUMBERS_SPAM)
@client.event
async def on_message(message):
def check(m):
for number in NUMBERS_SPAM:
return m.content == number and m.channel.send == message.channel.send
msg1 = await client.wait_for("message", check=check)
await message.channel.send("let's spam")
I thought it would work, but actually the bot only answers when i enter 1, although i want it to answer when he reads an int from 1 to 30
Thanks a lot to anyone who would be helping me out !!
So you want to prompt a user to spam x (user) y amount of times, keep it simple.
@client.command()
async def spam(ctx, user : discord.User, amount = 1):
await ctx.reply("Spamming {} {} times.".format(user,amount))
for i in range(amount): await user.send(i)
return
exits on first loop when number
is 1
– so it check only one value.
You should use if ... in ...
instead of for ... in ...
and ==
def check(m):
return (m.content in NUMBERS_SPAM) and (m.channel.send == message.channel.send)