Discord.py: Test if message.channel =

Created on 17 Nov 2017  路  4Comments  路  Source: Rapptz/discord.py

I can't seem to test if the message.channel is equal to so and so. I try printing the message.channel and it comes as "buffer_check" but if I try:
if message.channel == "buffer_check":
it always runs the else statement.
How would I check if the message is on a certain channel?

current code without client.run: https://hastebin.com/vedulawinu.py

question

Most helpful comment

python is a dynamically typed language. When things aren't working as you expect, try inspecting the types of the objects you are trying to compare, e.g. by printing them or using pdb

You might also find some of these resources useful for familiarizing yourself with python:
https://automatetheboringstuff.com/ (for complete beginners to programming)
https://learnxinyminutes.com/docs/python3/ (for people who know programming already)
https://docs.python.org/3/tutorial/ (official tutorial)
http://python.swaroopch.com/ (useful book)
see also: http://www.codeabbey.com/ (exercises for beginners)

All 4 comments

you used = instead of ==, = is for assignments, while == is for comparison

No, I used the right symbol. I just made a small example for perspective on this issue.

python is a dynamically typed language. When things aren't working as you expect, try inspecting the types of the objects you are trying to compare, e.g. by printing them or using pdb

You might also find some of these resources useful for familiarizing yourself with python:
https://automatetheboringstuff.com/ (for complete beginners to programming)
https://learnxinyminutes.com/docs/python3/ (for people who know programming already)
https://docs.python.org/3/tutorial/ (official tutorial)
http://python.swaroopch.com/ (useful book)
see also: http://www.codeabbey.com/ (exercises for beginners)

got it working by making it str(message.channel)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

synbitz picture synbitz  路  3Comments

j0hnmeow picture j0hnmeow  路  3Comments

adhoc92 picture adhoc92  路  3Comments

Nicba1010 picture Nicba1010  路  3Comments

TunaHobby picture TunaHobby  路  3Comments