Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我得到了这个错误:RuntimeWarning:从未等待过协同程序_Python_Discord_Discord.py - Fatal编程技术网

Python 我得到了这个错误:RuntimeWarning:从未等待过协同程序

Python 我得到了这个错误:RuntimeWarning:从未等待过协同程序,python,discord,discord.py,Python,Discord,Discord.py,在尝试运行我的discord bot时,我遇到此错误 这是我的密码 import discord from discord.ext import commands client = commands.Bot(command_prefix='+') @client.command(pass_context = True) async def ping(ctx): channel = bot.get_channel("826609837600931861")

在尝试运行我的discord bot时,我遇到此错误
这是我的密码

import discord

from discord.ext import commands

client = commands.Bot(command_prefix='+')


@client.command(pass_context = True)
async def ping(ctx):
    channel = bot.get_channel("826609837600931861")
    await channel.send('h')


client.login('XXXXXXXXXXXXXX')
错误:


RuntimeWarning:coroutine“Client.login”从未被等待过

客户端。login
是一个coroutine。您可以使用
asyncio

导入异步IO
#这里还有其他代码
asyncio.run(client.login('token'))
参考资料:

客户端。登录是一个协同程序。您可以使用
asyncio

导入异步IO
#这里还有其他代码
asyncio.run(client.login('token'))
参考资料:
您可以使用client.run()这将为您完成所有eventloop操作

import discord

from discord.ext import commands

client = commands.Bot(command_prefix='+')


@client.command(pass_context = True)
async def ping(ctx):
    channel = bot.get_channel("826609837600931861")
    await channel.send('h')


client.run('XXXXXXXXXXXXXX')
您可以使用user client.run()这将为您完成所有eventloop操作

import discord

from discord.ext import commands

client = commands.Bot(command_prefix='+')


@client.command(pass_context = True)
async def ping(ctx):
    channel = bot.get_channel("826609837600931861")
    await channel.send('h')


client.run('XXXXXXXXXXXXXX')

您好,我不知道如何在代码中实现这一点。我怎样才能使用asyncio来实现这一点呢?很简单,只需更改最后一行,您需要asyncio来运行协同程序,如果您不在异步函数中,您好,我不知道如何在代码中实现这一点。我该如何使用asyncio来实现这一点。很简单,只需更改最后一行,如果您不在异步函数中,则需要asyncio来运行协同程序谢谢您的反馈,但我的目标是让bot在特定通道中发送消息,然后脱机,我该如何做到这一点。请看on_ready事件。您可以在那里发送消息并使用.close()@JoeJay关闭bot,这实际上属于一个单独的问题,您的问题是您无法运行协同程序,我认为这两个答案都回答正确。请准确阐述您的问题和意图。感谢您的反馈,但我的目标是让机器人通过特定渠道发送消息,然后脱机,我将如何做到这一点。请看on_ready活动。您可以在那里发送消息并使用.close()@JoeJay关闭bot,这实际上属于一个单独的问题,您的问题是您无法运行协同程序,我认为这两个答案都回答正确。请准确阐述你的问题和意图。