Responding to DMs
This commit is contained in:
parent
e38a7532c3
commit
7046eb2576
@ -38,18 +38,22 @@ async def get_ai_response(prompt):
|
|||||||
async def on_ready():
|
async def on_ready():
|
||||||
print(f'{bot.user} has connected to Discord!')
|
print(f'{bot.user} has connected to Discord!')
|
||||||
|
|
||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
async def on_message(message):
|
async def on_message(message):
|
||||||
# Ignore messages from the bot itself
|
# Ignore messages from the bot itself
|
||||||
if message.author == bot.user:
|
if message.author == bot.user:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Check if the bot is mentioned in the message
|
# Respond to DMs or when mentioned in a server
|
||||||
|
if isinstance(message.channel, discord.DMChannel) or bot.user in message.mentions:
|
||||||
|
# For mentions, remove the bot mention from the message
|
||||||
if bot.user in message.mentions:
|
if bot.user in message.mentions:
|
||||||
# Remove the bot mention and get the actual prompt
|
|
||||||
prompt = message.content.replace(f'<@{bot.user.id}>', '').strip()
|
prompt = message.content.replace(f'<@{bot.user.id}>', '').strip()
|
||||||
|
else:
|
||||||
|
prompt = message.content.strip()
|
||||||
|
|
||||||
# If there's no prompt after mentioning the bot
|
# If there's no prompt
|
||||||
if not prompt:
|
if not prompt:
|
||||||
await message.channel.send("Hello! How can I help you?")
|
await message.channel.send("Hello! How can I help you?")
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user