如何修复python3.6.1中“Bot”对象没有“send_message”属性?

2024-04-19 20:06:04 发布

您现在位置:Python中文网/ 问答频道 /正文

所以,我一直在编写一个机器人程序更换python3.6.1和我遇到了一个问题。问题是,在我用bot连接到discord之后,我键入一个单词(cookie),它将使bot在discord服务器上执行一个操作。我使用的代码如下。以及错误代码

我的代码:

import discord
from discord.ext.commands import Bot
from discord.ext import commands
import asyncio
import time

TimeoutError

Client = discord.Client() #Initialise Client 
client = commands.Bot(command_prefix = "?") #Initialise client bot


@client.event 
async def on_ready():
print("Bot is online and connected to Discord") #This will be called
# when the bot connects to the server

@client.event
async def on_message(message):
    if message.content == "cookie":
        await client.send_message(message.channel, "cookie")


client.run("my discord bot token")

终端错误:

^{pr2}$

Tags: 代码fromimportclienteventmessageasynccookie