discord.py - Discord.py 在频道命令中取消固定消息?
问题描述
到目前为止,我得到的是:
@Bot.command()
async def unpin(ctx, amount = None):
await ctx.message.delete()
channel = str(ctx.channel)
x = 0
amount = int(amount)
if amount == 0:
await ctx.send("How many messages do you want to unpin, max is 50.")
else:
pins = await channel.pins()
for message in pins:
await message.unpin()
x+=1
x1 = str(x)
await ctx.send(f"Unpinned {x} messages from #{channel}")
我的问题在于pins = await channel.pins()
- 我不知道如何访问频道中的固定消息。如果有人可以提供帮助,将不胜感激。
解决方案
您将ctx.channel
in 返回到一个字符串。这就是您无法访问引脚的原因。如果您将行更改channel = str(ctx.channel)
为channel = ctx.channel
,您的问题将得到解决。
而且,您应该将参数更改amount=None
为amount=0
.
推荐阅读
- pact - PACT 节点 - ConsumerVersionSelector - 参与者和版本未兑现
- c++ - Qt:尝试将拖放添加到可编辑树模型示例不起作用
- javascript - 如何将正文添加到 JavaScript 部分?
- javascript - 从外部地图单击时显示信息窗口标记
- go - 如何实现 Golang 回调函数的接口?
- php - MySQL 数据库字段应为 datetime 时为 varchar
- javascript - 如何在悬停的旁边滑行
- ?
- angular - 限制角树组件中选择的节点数
- python - 如何导航到 BeautifulSoup 对象中的某些标签?
- laravel - Laravel - 不正确的表定义;只能有一个自动列,并且必须将其定义为键”