bot.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:ModTools 作者: MattBSG 项目源码 文件源码
def cmd_slowmode(self, message, author, server, channel_id, time_between, reason=None):
        """
        Usage: {command_prefix}slowmode #channel <time between messages> ["reason"]
        Puts the channel mentioned into a slowmode where users can only send messages every x seconds.
        To turn slow mode off, set the time between messages to "0"
        """
        if await self.has_roles(message.channel, author, server, command='slowmode'):
            if channel_id in self.server_index[message.server.id][12]:
                raise CommandError('ERROR: Channel ID is ignored. Unignore the channel before setting to slow mode')
            try:
                time_between = int(time_between)
            except:
                raise CommandError('ERROR: The time limit between messages isn\'t a number, please specify a real number')
            try:
                if channel_id in self.slow_mode_dict.keys():
                    if time_between == 0:
                        await self.delete_role(server, self.slow_mode_dict[channel_id]['channel_muted_role'])
                        del self.slow_mode_dict[channel_id]
                        await self.safe_send_message(discord.Object(channel_id), 'This channel is no longer in slow mode!')
                    else:
                        self.slow_mode_dict[channel_id]['time_between'] = time_between
                        await self.safe_send_message(discord.Object(channel_id), 'The delay between allowed messages is now **%s seconds**!' % time_between)
                else:
                    slowed_channel = discord.utils.get(server.channels, id=channel_id)
                    channel_muted_role = await self.create_role(server,
                                                                name=slowed_channel.name + 'SLOWROLE',
                                                                permissions=discord.Permissions(permissions=66560))
                    overwrite = discord.PermissionOverwrite()
                    overwrite.read_messages = True
                    overwrite.send_messages = False
                    await self.edit_channel_permissions(slowed_channel, channel_muted_role, overwrite)
                    await self.safe_send_message(discord.Object(channel_id), 'This channel is now in slow mode with a delay of **%s seconds**!' % time_between)
                    self.slow_mode_dict[channel_id] = {'time_between': time_between,
                                                       'channel_muted_role': channel_muted_role}
                await self.write_to_modlog(message, author, server, reason)
            except:
                raise CommandError('ERROR: Please make sure the syntax is correct and resubmit the command!')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号