【问题标题】:Discord.py(v 1.5.0) : TypeError: can't send non-None value to a just-started generatorDiscord.py(v 1.5.0) : TypeError: can't send non-None value to a just-started generator
【发布时间】:2021-03-26 11:37:07
【问题描述】:

所以我试图制作一个不和谐的机器人,我想制作一个向所有频道发送消息的命令。

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

起初(当我让机器人在线时),没有错误。但是当我运行命令时,没有输出不和谐,在控制台中,这是:

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

【问题讨论】:

    标签: python python-3.x string discord discord.py


    【解决方案1】:
    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 - 表示它是一个迭代器,要了解有关迭代器的更多信息,请查看this answer

    参考:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-06
      • 2013-11-13
      • 1970-01-01
      • 2021-11-25
      • 2020-09-26
      • 2022-12-02
      • 1970-01-01
      • 2022-12-27
      相关资源
      最近更新 更多