python - 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'
解决方案
使用说命令。
@bot.command()
async def say(ctx, *,message):
if not ctx.author.bot:
else:
pass
推荐阅读
- python - 如何强制 Python 导航到网页并打印所有锚点(a-html)
- java - 将 3 个链表合并为 1 个(Java)
- javascript - 如何在加载网页时隐藏 div
- ms-access - 标准中的 OnlyDigits 函数
- ubuntu - 无法使用 nginx 将子目录重定向到子域
- android - 我可以更改 ArCore 虚拟相机的姿势或在一个场景中有多个虚拟相机吗?
- powershell - Powershell:关于 %(百分号)的问题以及它在以下脚本片段中的工作方式
- elasticsearch - 将数据从 elasticsearch 传输到 kafka
- python - 没有名为 sh 的模块
- javascript - 处理 ReferenceError:geoip2 未在 jQuery 或 JavaScript 中定义