OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

TypeError: 'async_generator' object is not subscriptable in discord.py

  • Thread starter Thread starter Dauern
  • Start date Start date
D

Dauern

Guest
Im trying to make a command for my discord bot that gets the message content from a specific channel without using discord.ext, I have tried putting it inside my async def on_message(message) function and it doesnt want to work. I know discord.ext will be better for this but I still want to what I have been using. Heres my code:

Code:
TOKEN = 'MY_BOTS_TOKEN'
import discord
intents = discord.Intents.all()
client = discord.Client(intents=intents)
@client.event 
async def on_message(message):
    mychannel = client.get_channel(MYCHANNELID)
    content = (mychannel.history(limit=1))[0].content
    if message.content.startswith('.content'):
        await message.channel.send(content)
client.run(TOKEN)

I tried putting the mychannel = client.get_channel(MYCHANNELID) content = (m7channel.history(limit=1))[0].content into a different function and then calling onto it in message.channel.send(). I wasnt expecting it to work and I guessed correctly. I also tried putting (await mychannel.history(limit=1))[0].content) inside of message.channel.send() but it returned the same error as the title.
<p>Im trying to make a command for my discord bot that gets the message content from a specific channel without using discord.ext, I have tried putting it inside my async def on_message(message) function and it doesnt want to work. I know discord.ext will be better for this but I still want to what I have been using.
Heres my code:</p>
<pre><code>TOKEN = 'MY_BOTS_TOKEN'
import discord
intents = discord.Intents.all()
client = discord.Client(intents=intents)
@client.event
async def on_message(message):
mychannel = client.get_channel(MYCHANNELID)
content = (mychannel.history(limit=1))[0].content
if message.content.startswith('.content'):
await message.channel.send(content)
client.run(TOKEN)
</code></pre>
<p>I tried putting the <code>mychannel = client.get_channel(MYCHANNELID) content = (m7channel.history(limit=1))[0].content </code> into a different function and then calling onto it in <code>message.channel.send()</code>. I wasnt expecting it to work and I guessed correctly.
I also tried putting <code>(await mychannel.history(limit=1))[0].content)</code> inside of <code>message.channel.send()</code> but it returned the same error as the title.</p>
 

Latest posts

ن
Replies
0
Views
1
نعمان منذر محمود الجميلي
ن
S
Replies
0
Views
1
Sikandra
S
Top