0
votes

i made a class for my bots config and general things in my code, im tidy so, client is discord.Client() and bot. is my class in my bot class i stored some channel ids and then i noticed client.send_message(channelid, message) way is no longer supporting. however, i edited my channel id variables to

channel1=client.get_channel(channelid)

client=discord.Client() is over my class, its defined.

i used this to send message

await bot.channel1.send("hello world")

i was expecting an message in that channel but reality:

Task exception was never retrieved
future: <Task finished name='Task-2' coro=<bot2() done, defined at /path/to/file/bot.py:46> exception=AttributeError("'NoneType' object has no attribute 'send'")>
Traceback (most recent call last):
  File "/path/to/file/bot.py", line 53, in bot2
    await bot.channel1.send(fc)
AttributeError: 'NoneType' object has no attribute 'send'

briefly my channel1 definition is nonetype.. why?

and yes i use another async def in my code and run it because this code should run outside on_message() and should run async

i called my async function end of the file with

client.loop.create_task(bot())
client.loop.create_task(bot2())
client.loop.create_task(dead())
client.run(bot.token)
1
channel1 is defined. bot.channel1 is not defined.knosmos
channel1 is in class bot class bot: channel1=xxxnorahCii
Did you do self.channel1?knosmos
umm, i don't know what means that, in where i have to do that?norahCii
Where are you trying to use bot.channel1? inside a method?Ceres

1 Answers

0
votes

channel1 is notype object because it tried to defined before bot is ready

  await client.wait_until_ready()
  channel1=client.get_channel(id)