如何向特定频道发送消息?
为什么我会犯这个错误?我的ChannelID
是对的
代码:
from discord.ext import commands
client = commands.Bot(command_prefix='!')
channel = client.get_channel('693503765059338280')
@client.event
async def on_ready():
print('Bot wurde gestartet: ' + client.user.name)
#wts
@client.command()
async def test(ctx,name_schuh,preis,festpreis):
await channel.send(discord.Object(id='693503765059338280'),"Name:" + name_schuh +"\n Preis: " + preis +"\n Festpreis: " + festpreis)
错误:
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'send'
client
和channel
超出范围。您可以使用global
关键字进行恶意攻击:但是更好的选择是一个包含实例的处理程序类
出现错误的原因是在连接bot之前调用了
channel = client.get_channel()
,这意味着它将始终返回None
,因为它看不到任何通道(未连接)将其移动到命令函数内部,使其在调用命令时获得
channel
对象还请注意,自1.0版以来,snowflakes are now ^{} type instead of ^{} type 。这意味着您需要使用
client.get_channel(693503765059338280)
而不是client.get_channel('693503765059338280')
相关问题 更多 >
编程相关推荐