'How do I make a discord bot that logs chats in a specific channel?
I made a Discord botm but I can't figure out how I can have the bot send a message when something is being sent in any channel, the message would basically be [user] sent [message] in [channel]
(I am using replit.com to write the code)
Solution 1:[1]
you can do that by getting the channel id of the channel you want to get the messages from, and the id of the channel you want the messages to be logged in. Add the following code in the on_message function:
#id of channel to get messages from
cid1 = channel id goes here
#id of channel to log messages to
cid2 = other channel id goes here
#getting channel object from id:
logc = await client.get_channel(cid1)
if message.author == self.user:
return
if message.channel.id == cid1:
await logc.send(f'{message.author} sent {message} in {logc.name}')
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 | Danny |
