'Is there a way to have two commands with the same name?
I want to make a bot that says hi when someone says hi. I also want it to say hello. its just a project to make myself more familiar with discord.py but i cant use both. for example, i have code below that makes the bot say hi if someone else says hi, but i also want to do it for hello. now neither works because they both have the name on_message. i dont want to use commands (i have reasons but just trust me on this) so is there any way to do this?
client = discord.Client()
@client.event
async def on_ready():
print(f'Logged on as {client.user}!')
@client.event
async def on_message(message):
if message.content.startswith('hi'):
channel = message.channel
await channel.send('hi')
Solution 1:[1]
Well, you can not put two functions with the same name.
If you want to do this you will can try create a command.
You can create one like this:
client = discord.Client()
@client.event
async def on_ready():
print(f'Logged on as {client.user}!')
@client.command
async def hello(ctx):
await ctx.channel.send("Hello!")
@client.command
async def hi(ctx):
await ctx.channel.send("hi!")
To make this answer to a prefix put this as you client:
from discord.ext import commands
client = commands.Bot(command_prefix='your prefix', case_insensitive=True)
If you absolutly have to not put commands I suggest you try this:
@client.event
async def on_message(message):
if message.content.startswith('hi'):
channel = message.channel
await channel.send('hi')
elif message.content.startswith('hello'):
channel = message.channel
await channel.send('hello')
though i'm not sure this will work
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
