Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to make my discord bot only reply question in specific channel?

I want to make my discord bot only reply to question on a specific channel. Here is the example:

Channel A:

User A: Dream!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Discord Bot: You are Dream’s big fans? Oh me too!

Channel B:

User A: Dream!

Discord Bot: "No Respond"

I want to make something like this. If it is possible, please help me! This is part of my code:

import discord
import time
import random

client = discord.Client()

@client.event
async def on_ready():
    print('{0.user} has already login!'.format(client))

@client.event
async def on_message(message):
    name = message.author.display_name
    if message.author == client.user:
        return

    if message.content.startswith("Hey Rikky!"):
        await message.channel.send('Always Here!')

    if "Rikky, tell me a joke" in message.content:
        await message.channel.send("I'm sorry, I'm not good at telling someone jokes")

client.run('My token')

Thanks for spending so much time reading this question! Thank you! (I’m using discord.py)

>Solution :

Just check the message’s channel id with message.channel.id before replying:

if message.content.startswith("Hey Rikky!") and message.channel.id == "YourChannelId":
    await message.channel.send('Always Here!')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading