Ask coding questions

← Back to all posts
How to get a channel inside on_message without bot | Discord.py
DwellerIgor (1)

Hello! It is me again. File currency.py from line 87 to 99. I have a function that adds credits to someone when they send a message and I have a spam-channel, so I don't want people to farm credits in spam-channel.

I did: channel = discord.utils.get(message.guild.channels, id = 819705815090200646) if channel.id != 819705815090200646: await self.add_credits(message.author) print("yes2")

But the bot doesn't any add any credits this way in ANY channel. And if I type else: then bot adds credits in every channel, so the bot thinks that every channel has the same id. I need one specific channel where you don't get the credits, but you do in others.

Thank you! Sorry for bothering you!
P.S. Coder100 thank you already!

Comments
hotnewtop
Coder100 (18882)

but you can also do print(channel.id) to debug what channel.id is!

Coder100 (18882)

I believe you should compare it with the string version, like this:

if channel.id != '819705815090200646': await self.add_credits(message.author) print("yes2")

i do believe that channel.id is a string and of course a number will never equal a string

DwellerIgor (1)

hello! sorry for answering too late, but no. This is not the case. When I print channel.id it gives me the same id channel has, but I need that credits function doesn't work in this channel, but it somehow works. I also tried string, but I get the same result. The bot checks channel, but he ignores !=. Is there any other way of doing this? Thanks @Coder100

Coder100 (18882)

did you read my other answer
it will provide valuable insight. @DwellerIgor

DwellerIgor (1)

are you talking about print(channel.id) answer? i read both @Coder100

DwellerIgor (1)

nice i fixed that: if message.channel.id != channel.id: await self.add_credits(message.author) @Coder100

DwellerIgor (1)

is there any course to learn python very good, because im kinda ok, but i want to be better @Coder100

Coder100 (18882)

well
you can search one up on google -- they'll all work I suppose @DwellerIgor