Ask coding questions

← Back to all posts
Is there
h
Coolboy62ksi (1)

Hello is there away you can make your discord.py bot speak to people when they say something without the prefix?

Answered by InvisibleOne (3215) [earned 5 cycles]
View Answer
Comments
hotnewtop
InvisibleOne (3215)

Yes there is

@client.event
async def on_message(message):
  if message.author.bot:
    return
  if message.content == 'spam':
    await message.channel.send("Hey! No spam!")

Just make sure you include 'await client.process_commands(message)or else your commands won't work after you use anon_message()` event

Coolboy62ksi (1)

You still have access to my bot i think if you would not mind helping [email protected]

InvisibleOne (3215)

I added the code to do messages, let me know if everything works @Coolboy62ksi

Coolboy62ksi (1)

@InvisibleOne it works perfectly thanks for the help

Coolboy62ksi (1)

Question @InvisibleOne if i added anther one of them events you have added to make my bot speak without its prefix when someone types would the other one stop working and how would i make more then one response

InvisibleOne (3215)

You can only have one on_message() function, but you can put multiple elif statements under that code, here's an example:

@client.event
async def on_message(message):
  if message.content == 'bob':
    await message.channel.send("Bob lol")
  elif message.content == 'another thing':
    await message.channel.send("Another thing")

Coolboy62ksi

Coolboy62ksi (1)

So if i put elif i can put as many responses as i [email protected]

Coolboy62ksi (1)

I want my bot to be able to speak to the people thsts added it while using its commands with prefix

InvisibleOne (3215)

Yeah, after the first if, then you can do elif (which means else if) and then a condition, and then what you want it to do if that condition is true, like

if 1+1 == 2:
  print("True")
elif 1+1 == 1:
  print("Hmmm...")
else:
  print("This will happen if neither are true")

@Coolboy62ksi

Coolboy62ksi (1)

@InvisibleOne you want to do a demonstration in my bots code you lost me haha still a beginner sorry to be a pest

InvisibleOne (3215)

You're not a pest, I don't mind doing the code. @Coolboy62ksi

Coolboy62ksi (1)

My bot is actually on top.gg you use discord? @InvisibleOne

Coolboy62ksi (1)

@InvisibleOne do you know how to code python dashboard for the discord bot?

InvisibleOne (3215)

Not really, I sortof made one once, but all it was really doing was connecting to the same database I used to store data, I wouldn't call it a dashboard. @Coolboy62ksi

Coolboy62ksi (1)

Ok @InvisibleOne im trying to find out how to make a dashboard