Python 当我试图发送不一致的消息时,出现语法错误

Python 当我试图发送不一致的消息时,出现语法错误,python,discord,discord.py,Python,Discord,Discord.py,我无法运行该程序,只是出现语法错误。我正试图向特定通道发送消息,但由于某种原因ch变量会亮起红色。我是新来的,我不是很好 ch = client.get_channel(12345642256905728) await ch.send('hello') 必须从函数中调用wait。如果您不是从函数中调用wait,则会出现如下错误: >>> import asyncio >>> await asyncio.sleep(1) File "<stdi

我无法运行该程序,只是出现语法错误。我正试图向特定通道发送消息,但由于某种原因ch变量会亮起红色。我是新来的,我不是很好

ch = client.get_channel(12345642256905728)
await ch.send('hello')

必须从函数中调用wait。如果您不是从函数中调用wait,则会出现如下错误:

>>> import asyncio
>>> await asyncio.sleep(1)
File "<stdin>", line 1
    await asyncio.sleep(1)
                ^
SyntaxError: invalid syntax
导入异步IO >>>等待asyncio.sleep(1) 文件“”,第1行 等待asyncio.sleep(1) ^ SyntaxError:无效语法 要使用“wait”,必须在异步函数中使用它。所以你可以这样做:

async def sendMessage(message):
    ch = client.get_channel(12345642256905728)
    await ch.send(str(message))

“str(message)”只是一个安全预防措施,因为在使用ch.send()时需要发送字符串。

您可以发布完整的回溯吗?没有它很难帮助它甚至无法运行。它只是给了我一个“无效语法”,而ch灯亮了,如果它没有运行,它一定会给你一个回溯,你甚至说它告诉你“无效语法”。我对discord的api了解不多,但我想您使用的是discord.py?也许你可以试试客户端。获取_频道('1234562256905728')啊错误,如果没有你的不描述性和普遍的地域性,我们该怎么办?哦,我知道:简化编程过程
import discord 
from discord.ext import commands
from discord.utils import get

bot = commands.Bot(command_prefix='Your perfix', description="Your description")

# You need to do @bot.command() because you have the bot = commands.Bot if you don't like it you can change it to client
@bot.command()
async def test(ctx):
    # Ctx stands for context and where the message came from
    ctx.channel.send("What you want the bot to send after you did your prefix command")
    # For example if your bots prefix is ! you need to do !test for it