python - 如何在调用函数时使用 discord.py 添加反应?
问题描述
我一直在使用 discord.py,我想创建一个在调用命令时与一组特定表情符号做出反应的函数。假设前缀是//
.
如果我想调用 //dinosauce,我希望机器人用:thumbsup
and做出反应:thumbsdown
。我该怎么做呢?
这是我的代码:
@client.command()
async def dinosauce(ctx, *, message):
emojis = [':thumbsup:', ':thumbsdown:']
await discord.Message.add_reaction(emoji=emojis)
解决方案
您可以通过\:thumbsup:
在 discord 中使用并复制过去来获取表情符号。
@client.command()
async def dinosauce(ctx, *, message):
await ctx.message.add_reaction('')
await ctx.message.add_reaction('')
在另一种方法中,您可以让机器人发送消息并删除原始消息。
@client.command()
async def dinosauce(ctx, *, message):
await ctx.message.delete()
msg = await ctx.send(message)
await msg.add_reaction('')
await msg.add_reaction('')
参考:
推荐阅读
- neo4j - 使用 C#neo4j 客户端将关系属性添加到返回节点?
- scala - 如何执行单个嵌套的 ScalaTest Suite?
- python - 获取列表中可用的免费余额
- kubernetes - 在 kustomization.yaml 中排除资源
- twitter - 等待 Twitter 的 API 限制重置后再继续
- javascript - 如何计算输入栏的内容?- 反应JS
- vue.js - vue 3 使用 Vuex 和路由器的服务器端渲染
- java - 使用java从Array中过滤id值
- javascript - Vue.js 中 setInterval 的功能
- java - 编年史队列上的 StreamCorruptedException 使队列无法使用