Reputation: 3
so i am trying to make a discord bot with discord,.py and i want the bot to say something when someone sends a message that contains a certain string. this is what i want to happen
@client.event
async def on_message(msg):
if 'i' in msg:
channel = client.get_channel("742261026686500896")
await channel.send("i")
i get this error
TypeError: argument of type 'Message' is not iterable
how would i go about doing this?
Upvotes: 0
Views: 1083
Reputation: 566
@client.event
async def on_message(msg):
if 'i' in msg:
channel = client.get_channel("742261026686500896")
await channel.send("i")
The discord Message
is an uniterable object (the reason you are getting the error). You are not accessing the information properly. The Message
object contains information on the other, channel, etc.
You can check the docs on this topic, here.
To access the content of the message, you should use msg.content
.
Then, you can run the test on that. Example:
@client.event
async def on_message(msg):
if 'i' in msg.conent:
channel = client.get_channel("742261026686500896")
await channel.send("i")
Upvotes: 1
Reputation: 3219
msg
is an object with several attributes. The text portion is found in msg.content
. Try this:
@client.event
async def on_message(msg):
if 'i' in msg.content:
channel = client.get_channel("742261026686500896")
await channel.send("i")
Upvotes: 1