python - Discordpy 商店角色以字符串形式提及
问题描述
所以我有这个命令可以让机器人在我想要的任何频道中写入,问题是我也希望能够提及它,所以我尝试更改以 @ 开头的 args 并将其转换为角色提及,但似乎我不能只在 args 中存储角色提及。有什么建议可以通过提及来更改某些参数吗?
async def echo(ctx, id, *echowords: str):
if ctx.message.author.id in [212620735754010624]:
sendchannel = client.get_channel(int(id))
for i in range(len(echowords)):
if echowords[i].startswith("@ "):
echowords[i] = get(
sendchannel.guild.roles, name=echowords[i].replace("@ ", "")
).mention
await sendchannel.send(" ".join(echowords[:]))
else:
await ctx.send("Bot developers only :<")
解决方案
最后,这一切都使用列表而不是元组解决了。
async def echo(ctx, id, *echowords: str):
if ctx.message.author.id in [212620735754010624]:
msg = list()
sendchannel = client.get_channel(int(id))
for i in range(len(echowords)):
if echowords[i].startswith("@ "):
msg.append(
get(
sendchannel.guild.roles, name=echowords[i].replace("@ ", "")
).mention
)
else:
print(str(i))
msg.append(echowords[i])
await sendchannel.send(" ".join(msg[:]))
else:
await ctx.send("Bot developers only :<")
推荐阅读
- node.js - LocalStorage 不会在 MERN 应用程序中的页面刷新时保持更新
- c - 将 char 数组从消息队列转换为 int 数组
- mysql - 带外键的 SQL 查询(缺失数据,返回默认值)
- inheritance - 与默认方法和字段的接口
- laravel - dockerizing Laravel 应用程序的问题 - 数据库主机数组为空
- python - 如何在python中从目标数据跟踪到源数据?
- eclipse - 在 Tomcat 上运行 Vaadin (maven) 示例项目的问题
- apache-kafka - 通过在 ksqlDB 中翻转窗口生成零计数的可能方法
- r - R,从图中推断平均分数
- javascript - 在 WEBGL 片段着色器中确定屏幕的中心