當前位置: 首頁>>代碼示例>>Java>>正文


Java Message.Attachment方法代碼示例

本文整理匯總了Java中net.dv8tion.jda.core.entities.Message.Attachment方法的典型用法代碼示例。如果您正苦於以下問題:Java Message.Attachment方法的具體用法?Java Message.Attachment怎麽用?Java Message.Attachment使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net.dv8tion.jda.core.entities.Message的用法示例。


在下文中一共展示了Message.Attachment方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: action

import net.dv8tion.jda.core.entities.Message; //導入方法依賴的package包/類
@Override
public void action(String head, String[] args, MessageReceivedEvent event)
{
    AccountManagerUpdatable manager = Main.getShardManager().getJDA().getSelfUser().getManagerUpdatable();
    if(event.getMessage().getAttachments().isEmpty()) return;

    Message.Attachment attachment = event.getMessage().getAttachments().get(0);
    try
    {
        File file = new File(attachment.getFileName());
        attachment.download(file);

        Icon icon = Icon.from(file);
        manager.getAvatarField().setValue(icon).update().complete();

        MessageUtilities.sendPrivateMsg("Updated bot avatar!", event.getAuthor(), null);
        file.delete();
    }
    catch (IOException e)
    {
        Logging.exception(this.getClass(), e);
        MessageUtilities.sendPrivateMsg("Failed to update bot avatar!", event.getAuthor(), null);
    }

}
 
開發者ID:notem,項目名稱:Saber-Bot,代碼行數:26,代碼來源:AvatarCommand.java

示例2: onGuildMessageReceived

import net.dv8tion.jda.core.entities.Message; //導入方法依賴的package包/類
@Override
public void onGuildMessageReceived(GuildMessageReceivedEvent event)
{
    //TODO: Automod!
    /*
    Want the following:
        * Configurable auto deleting of links and file uploads
        * Whitelist/Blacklist for links and bad words
        * Regex on bad words (print to the log what words were matched in the message
        * Configurable muting when someone's done bad enough things:
            * Posted too many bad words within X time (default 5mins?)
            * Posted too many messages (configurable) within X time (default 5 messages in 2s?)
            * Posted too many duplicate characters in a message (default >60% similar characters in a message?)
     */

    Message message = event.getMessage();
    User author = message.getAuthor();

    //Ignore Admins and Moderators
    if(MDCBot.isMemberBotModerator(event.getGuild().getMember(author)))
        return;

    String content = message.getContent();
    TextChannel channel = event.getChannel();
    String channelName = channel.getName();

    if(checkLinks(channelName, message))
        deleteMessage(message, "Deleted message containing link from member %s (%s) in %s (%s):%s", author.getAsMention(), author.getName(), channel.getAsMention(), channelName, content);

    if(checkFiles(channelName, message))
    {
        StringBuilder sb = new StringBuilder();
        for(Message.Attachment a : message.getAttachments())
            sb.append("\n").append(a.getUrl());
        deleteMessage(message, "Deleted file posted by member %s (%s) in %s (%s):%s", author.getAsMention(), author.getName(), channel.getAsMention(), channelName, sb.toString());
    }

    if(checkSpamCharacters(channelName, content))
        deleteMessage(message, "Deleted message containing spammed characters from member %s (%s) in %s (%s):%s", author.getAsMention(), author.getName(), channel.getAsMention(), channelName, content);

    if(checkSpamMessages(channelName, message))
        for(Message m : messageSpamCache.get(author.getIdLong()))
            deleteMessage(m, "Deleted message due to spam from member %s (%s) in %s (%s):%s", author.getAsMention(), author.getName(), channel.getAsMention(), channelName, m.getContent());

    if(checkBadWords(channelName, content))
        deleteMessage(message, "Deleted message due to bad words from member %s (%s) in %s (%s):%s", author.getAsMention(), author.getName(), channel.getAsMention(), channelName, content);
}
 
開發者ID:thebrightspark,項目名稱:MDC-Discord-Bot,代碼行數:48,代碼來源:AutomodListener.java


注:本文中的net.dv8tion.jda.core.entities.Message.Attachment方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。