Comments (3)
🤖
Hi @wushd! I'm Dosu, a friendly bot here to help you out with your questions and issues on Wechaty while we wait for a human maintainer. I'm here to make your experience with Wechaty as smooth as possible. It's nice to meet you!
是的,可以改变在Wechaty发送群消息时@人的位置。@人的位置取决于你在say
方法中放置联系人的位置。如果你想把它放在文字的最后面,可以在文字后面放置联系人。以下是一个例子:
const contact = await bot.Contact.find({name: 'lijiarui'}) // 将'lijiarui'更改为房间的任何成员
await room.say('Hello world!', contact)
在这个例子中,'Hello world!'是消息,contact
是你想要@的联系人。@将被放在文本的最后,因为它在say
方法中被放在了文本后面。
关于say
方法在Wechaty中如何处理消息中@提及的位置,say
方法通过接受一个可选的mention
参数来处理消息中@提及的位置。这个参数可以是一个ContactInterface
对象或一个ContactInterface
对象的数组。当提供了这个参数时,提到的联系人将在消息中被@。
这是相关的代码部分:
/**
* 回复文本或媒体文件消息给发送者。
*
* @param {(string | ContactInterface | FileBox | UrlLinkInterface | MiniProgramInterface | LocationInterface)} textOrContactOrFile
* 发送文本,联系人,或文件给机器人。
* @param {(ContactInterface|ContactInterface[])} [mention]
* 如果这是一个房间消息,当你设置mention参数时,你可以在房间中`@`联系人。
* @returns {Promise<void | MessageInterface>}
*/
async say (
textOrContactOrFile : Sayable,
mention? : ContactInterface | ContactInterface[],
): Promise<void | MessageInterface> {
log.verbose('Message', 'say(%s, %s)', textOrContactOrFile, mention)
const sayable = messageToSayable(textOrContactOrFile)
let mentionIdList: string[] = []
if (mention) {
mentionIdList = Array.isArray(mention)
? mention.map(c => c.id)
: [mention.id]
}
const receiver = this.room() || this.talker()
if (!receiver) {
throw new Error('no receiver')
}
const receiverId = receiver.id
const messageId = await this.wechaty.puppet.messageSend(
receiverId,
sayable,
mentionIdList,
)
if (typeof messageId === 'string') {
return this.wechaty.Message.load(messageId)
}
return
}
在这段代码中,如果提供了mention
参数,它会被转换为一个联系人ID的数组(mentionIdList
)。然后,这些ID被传递给puppet的messageSend
方法,该方法处理实际的消息发送。puppet负责格式化消息,以在正确的位置包含@提及。
参考源码:
Sources
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
If you want to continue the conversation, start your reply with @dosu-bot.
from wechaty.
有没有示例代码能参考一下
from wechaty.
如果我想实现@多个人要怎么实现呢,例:你好@A@B@C
from wechaty.
Related Issues (20)
- 企业微信遇到的问题 HOT 4
- 重新扫码padlocal两三天了还没有人修复嘛,wechat bad request error: 你的应用版本过低,请升级至最新版本后再登录。点击“确定”后将跳转至最新版下载页面,登录不了咯, HOT 7
- 我想监听群聊中其他人进入群聊的事件,是否有提供呢 HOT 5
- 为什么使用bot.Contact.findAll()方法查找到的联系人名称都是空呢 HOT 8
- 你的应用版本过低,请升级至最新版本后再登录。点击“确定”后将跳转至 最新版下载页面,依赖都是最新版的这个怎么解决呢 HOT 2
- 你的应用版本过低,请升级至最新版本后再登录。点击“确定”后将跳转至 最新版下载页面,依赖都是最新版的这个怎么解决呢? HOT 2
- 告诉我现在个人微信可以支持发送语音的所有puppet HOT 2
- Workpro 企业微信小程序消息发送失败
- 如何识别 引用 类型的消息,目前用text获取不到 HOT 1
- 【wechaty问题交流微信群】一起讨论,吐槽,解决wechaty中遇到的坑 HOT 1
- contact.friend() HOT 1
- 什么时候可以支持消息的引用啊
- updating README
- PadLocal是不是带着小姨子跑路了 HOT 1
- 短时间多次调用room.say发送图片,发送间隔很长 HOT 5
- 你的应用版本过低,请升级击“确定”后将跳转至最新版下载页面。 HOT 1
- wechaty版本1.18+怎么获取用户唯一标识? HOT 1
- 如何强制刷新群聊列表? HOT 3
- 消息发送完成后,没有实际展示,也没有报错
- 经常中断 uncaughtException GError [AxiosError]: timeout of 60000ms exceeded
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wechaty.