我对编程完全陌生,所以请指出您能看到的所有内容,这是错误的。 我正在尝试为不和谐制作一个机器人,它每小时左右发送一条消息(稍后可能会更改)。 我查看了别人的代码并尝试使用它。我已经安装了 discord-ext-alternatives、discord.py NuGet 和其他一些,如您在图像右侧看到的那样。 不知何故,Visual Studio 无法识别这些 NuGet(如您所见)。 我做错了什么?提前谢谢你们。 (What I currently have)
from discord.ext import
bot = commands.Bot("!")
target_channel_id = the channel id
@tasks.loop(hours=1)
async def called_once_a_day():
message_channel = bot.get_channel(target_channel_id)
print(f"Got channel {message_channel}")
await message_channel.send("my message")
@called_once_a_day.before_loop
async def before():
await bot.wait_until_ready()
print("Finished waiting")
called_once_a_day.start()
bot.run("bot token")
答案 0 :(得分:0)
问题不在于 Visual Studio 没有识别模块,而是您错误地导入了它们。
而不是这样做:
from discord.ext import
您需要执行以下操作来导入 discord.py 和执行任务和命令所需的模块:
import discord
from discord.ext import tasks, commands