如何在discord.py(rewrite)中进行频道删除反应?

时间:2020-06-21 11:20:52

标签: python python-3.x discord discord.py-rewrite

因此,我创建了一个命令@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ,该命令创建了一个新的频道,该频道具有作者和设置了管理员的所有权限,属于特定类别。现在,我想创建一个删除工单的命令-!vx new。这是我想出的代码,它可以工作,但问题是它可以从票证中的任何用户处收到“是”。

!vx close

我希望键入@client.command(name='close', aliases=['delete']) @commands.has_permissions(administrator=True) async def close(ctx): await ctx.send("Do you want to delete this channel?") @commands.Cog.listener() async def on_reaction_add(self, reaction, user: discord.Member): def check(reaction, user): name_list = [] for emoji in reaction.message.reactions: name_list.append(emoji.emoji) return '✅' in name_list and reaction.message.author.id == MyBotID and reaction.message.content == "Do you want to delete this channel?" and user.guild_permissions.administrator if check(reaction, user): await ctx.send("K!") await ctx.channel.delete() 的用户使用叉号/勾号做出反应,如果作者用叉号做出反应,它将关闭票证,如果作者用叉号做出反应,则不会关闭。

编辑-上面的代码也不起作用。

1 个答案:

答案 0 :(得分:2)

您可以从函数的上下文(ctx)中获取成员对象,并从DataFrame中获取消息。因此您可以将检查功能设为:

import pandas as pd
import numpy as np

# Dummy function
def new_rows():
    return [['Comp1','Comp1'],['1h','1W']]

# Does not work
class DatF1(pd.DataFrame):

    def __init__(self,meth,data=None):
        cmidx = pd.MultiIndex.from_arrays([['Index', 'Index'],['First', 'Last']])
        rmidx = pd.MultiIndex(levels=[[],[]], codes=[[],[]],
                          names=['Component','Interval'])
        super().__init__(data=data, index=rmidx, columns=cmidx, dtype=np.datetime64)
        self.meth=meth

    def refresh(self):
        values = [[pd.Timestamp('2020/02/10 8:00'),pd.Timestamp('2020/02/10 8:00')],
                  [pd.Timestamp('2020/02/11 8:00'),pd.Timestamp('2020/02/12 8:00')]]
        rmidx = self.meth()
        self[rmidx] = values

ex1 = DatF1(new_rows)
ex1.refresh()

KeyError: "None of [MultiIndex([('Comp1', 'Comp1'),\n            (   '1h',    '1W')],\n           names=['Component', 'Interval'])] are in the [index]"

对于表情符号位,您可以在client.wait_for()事件中放入if语句,以类似“如果我(机器人)发出的消息,并且消息内容是关闭且响应表情符号是同意的”这样的内容AND用户具有“管理员”权限“

表情符号要求: 看起来像这样。

return m.content.lower() == 'yes' and ctx.message.author == m.author