Reputation: 25
I m trying to listen to all messages from specific channels inside guilds that i m not owner, i started to trying listen to all messages with the code below, without success. How can i do that if possible using the channel id?
Thank you!
import discord
client = discord.Client()
guild = discord.Guild
messages = []
print("Bot started")
@client.event
async def on_message(message):
msg = message.content
if msg != "" :
messages.append(msg)
while True:
print(messages)
client.run('TOKENHERE')
Upvotes: 0
Views: 11833
Reputation: 2289
Every message
object has the channel it was sent in as an attribute. You can simply compare the ids, and if they match, run your code.
Also be sure that you have the messages
intent, in order for the on_message()
event to work, like said here.
import discord
intents = discord.Intents.default()
intents.messages = True
client = discord.Client(intents = intents)
guild = discord.Guild
messages = []
print("Bot started")
@client.event
async def on_message(message):
channelIDsToListen = [ 12345, 54321 ] # put the channels that you want to listen to here
if message.channel.id in channelIDsToListen:
if message.content != "" :
messages.append(message.content)
print("New message: " + message.content)
client.run('TOKENHERE')
Upvotes: 1