Demotry
Demotry

Reputation: 907

Python How to send individual message for servers

Hello i want to send a individual message for servers when command has invoked.

List = ['Server 1 ID' : 'Message 1', 'Server 2 ID' : 'Message 2',]

@bot.event
async def on_message(message):
    if message.content.startswith(("!Ping")):
        if message.server.id in List:
            await bot.send_message(message.channel, "Pong")

So if message server id in that list bot should send that particular message to that server.

Upvotes: 1

Views: 67

Answers (1)

Patrick Haugh
Patrick Haugh

Reputation: 61042

Use a dictionary instead of a list

messages = {'1234': "Hello server 1!", '5678': 'This is the message for server 2.'}

@bot.event
async def on_message(message):
    if message.content.startswith(("!Ping")):
        if message.server.id in messages:
            await bot.send_message(message.channel, messages[message.server.id])

Upvotes: 2

Related Questions