discord-bot:未定义名称通道


import os
import discord
import random
from prettytable import PrettyTable
from PIL import Image

client = discord.client()

@client.event
async def on_ready():
print("We have logged in as {0.user}".format(client))

@client.event
async def on_message(message):
if message.author == client.user:
return

if message.content.startswith("$picture"):

await channel.send(file=discord.File("images.jpg"))


client.run(os.getenv('TOKEN'))

你好,这是我第一次使用堆栈溢出,如果我的帖子有一些错误,我提前道歉,所以我试图让我的不和上传一张照片$图片";在聊天框中,但我在写着await channel.send(file=discord.File("images.jpg"))Saying"未定义的命名"通道";我试着查了一下,但找不到什么。有什么想法吗?非常感谢。

您需要执行message.channel.send()而不是channel.send()

所以不是

@client.event
async def on_message(message):
if message.author == client.user:
return

if message.content.startswith("$picture"):

await channel.send(file=discord.File("images.jpg"))

你可以做

@client.event
async def on_message(message):
if message.author == client.user:
return

if message.content.startswith("$picture"):

await message.channel.send(file=discord.File("images.jpg"))

最新更新