簡體   English   中英

Discord.py(v 1.5.0): TypeError: can't send non-None value to a just-started generator

[英]Discord.py(v 1.5.0) : TypeError: can't send non-None value to a just-started generator

所以我試圖制作一個 discord 機器人,我想制作一個向所有頻道發送消息的命令。

    @client.command(pass_context = True)
async def send_all(ctx):
    channel = client.get_all_channels()
    await channel.send("I sent this to all channels")

起初(當我讓機器人在線時),沒有錯誤。 但是當我運行命令時,在 discord 和控制台中沒有出現 output 出現:

Traceback (most recent call last):
  File "C:\Users\User\anaconda3\lib\site-packages\discord\ext\commands\bot.py", line 903, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\User\anaconda3\lib\site-packages\discord\ext\commands\core.py", line 859, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\User\anaconda3\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: can't send non-None value to a just-started generator
for channel in client.get_all_channels():
    # get_all_channels also include voice channels, just check if it's not
    if isinstance(channel, discord.TextChannel):
        await channel.send('whatever')

你也可以:

for guild in client.guilds:
    for channel in guild.text_channels:
        await channel.send('whatever')

Bot.get_all_channels產生GuildChannel obj - 意味着它是一個迭代器,要了解有關迭代器的更多信息,請查看此答案

參考:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM