【发布时间】:2023-01-19 19:07:22
【问题描述】:
我想向特定频道发送消息。我得到了频道,但是当我尝试发送消息时出现此错误:
Traceback (most recent call last):
File "C:\Users\nikit\PycharmProjects\Phantom_Shop\discord\ui\view.py", line 425, in _scheduled_task
await item.callback(interaction)
File "C:\Users\nikit\PycharmProjects\Phantom_Shop\temporary_classes.py", line 200, in buy_callback
await channel.send("Test")
AttributeError: 'NoneType' object has no attribute 'send'
我在一个单独的文件中执行此操作(特别是在视图中的按钮回调中) 这是使用的单独文件的一部分:
from temporary_bot import client
channel = client.get_channel(channel_id)
await channel.send("Test")
这是主要文件:
client = discord.Client(intents=intents)
tree = app_commands.CommandTree(client)
channel = client.get_channel(1062092063128166571)
@client.event
async def on_ready():
await tree.sync()
print('We have logged in as {0.user} bot'.format(client))
@tree.command(name = "start", description = "Start the bot")
async def first_command(interaction):
view = Menu_View()
view.add_item(url)
keys = data["profiles"]
if f"{interaction.user}" in keys:
print("Account already in database")
else:
data["profiles"][f"{interaction.user}"] = {}
data["profiles"][f"{interaction.user}"]["balance"] = 0
print("This is bullshit")
data["profiles"][f"{interaction.user}"]["spent"] = 0
data["profiles"][f"{interaction.user}"]["bought_product"] = 0
with open("profiles.json", "w") as file:
json.dump(data, file)
menu = make_menu(interaction.user.avatar)
await interaction.response.send_message(embed=menu, view=view)
if __name__ == "__main__":
client.run(TOKEN)
我尝试在主文件中创建变量,但它犯了同样的错误。 我使用一个数字作为我的频道 ID,我在其他频道上尝试过,同样的事情。
【问题讨论】: