首页 > 解决方案 > discord.py - 通过控制台发送消息

问题描述

好的,我想要这样我可以在控制台中的特定服务器和通道中发送消息。我在其他帖子中看到如何在特定服务器和通道上发送消息,但它们来自不和谐应用程序而不是控制台。有人能帮我吗?

我想要,所以我输入msg [server-id-here] [channel-name] [message]例如

味精 493121776402825219 你好

我有代码,但有错误

@bot.event
async def on_ready(ch, *, msg):
while msg:
  channel = bot.get_channel(ch)
  msg=input("Mensagem: ")
if channel:
  await bot.send_message(channel, msg)
else:
  await bot.say("I can't find that channel")

输出的错误

TypeError: on_message() missing 1 required positional argument: 'ch'

标签: pythondiscord.py

解决方案


使用说命令。

@bot.command()
async def say(ctx, *,message):
   if not ctx.author.bot:

   else:
      pass

推荐阅读