【发布时间】:2022-01-10 19:10:45
【问题描述】:
当我尝试向频道发送消息时,它不起作用。有谁知道为什么?
这是我正在使用的命令。这只是不工作部分的代码块。
@bot.command(pass_context=True)
async def test2(ctx):
await ctx.message.delete()
print("The Test is being started")
Channel = config['bot']['id1']
await Channel.send("test2")
在我的配置文件中,我有这个
[bot]
id1= 916845047CENSORED
当我尝试运行它时,我得到了这个错误:
The test is being started
Ignoring exception in command test2:
Traceback (most recent call last):
File "C:\Python\Python38\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "c:/Users/jp/Desktop/DISCORD BOT/bot.py", line 224, in test2
await Channel.send("test2")
AttributeError: 'str' object has no attribute 'send'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Python\Python38\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "C:\Python\Python38\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Python\Python38\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'str' object has no attribute 'send'
如果有人知道如何解决这个问题,我会非常感谢你
编辑:
解决方法是:
如果它来自 txt 文件/配置,则将 int 添加到频道 ID
@bot.command(pass_context=True)
async def test2(ctx):
await ctx.message.delete()
Channel_Id = config['bot']['id1']
print("Test is being started")
Chanel = bot.get_channel(int(Channel_Id))
await Chanel.send("test2")
【问题讨论】:
标签: python discord discord.py