twitch4j / twitch4j.github.io

Twitch4J Page
http://twitch4j.github.io
MIT License
4 stars 14 forks source link

sendPrivateMessage not actually sending the whisper #19

Closed duncte123 closed 9 months ago

duncte123 commented 2 years ago

Prerequisites

Expected Behavior

The bot sends me a whisper containing the text I provide

var event = ChannelMessageEvent instance
// this.client is an instance of TwitchClient

// neither of these work
this.client.getChat().sendPrivateMessage(
    event.getUser().getName()/*.toLowerCase()*/, // lower/non lower does not make a difference
    "the word"
);
event.getTwitchChat().sendPrivateMessage("duncte123", "test 123");

Current Behavior

The bot never sends a whisper

Log output / Stacktrace

There is no useful info here

> Task :Main.main()
20-02-2022 13:22:36 main       Main       INFO   Booting bot
20-02-2022 13:22:37 main       EventManag INFO   Auto Discovery: SimpleEventHandler registered!
20-02-2022 13:22:37 main       URLConfigu WARN   No URLs will be polled as dynamic configuration sources.
20-02-2022 13:22:37 main       URLConfigu INFO   To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
20-02-2022 13:22:40 ReadingThr TwitchChat INFO   Connecting to Twitch IRC wss://irc-ws.chat.twitch.tv:443
20-02-2022 13:22:41 ReadingThr TwitchPubS INFO   Connecting to Twitch PubSub wss://pubsub-edge.twitch.tv:443
20-02-2022 13:22:41 ReadingThr TwitchPubS INFO   Connected to Twitch PubSub wss://pubsub-edge.twitch.tv:443
20-02-2022 13:22:41 main       DynamicPro INFO   DynamicPropertyFactory is initialized with configuration sources: com.netflix.config.ConcurrentCompositeConfiguration@2c30b71f
20-02-2022 13:22:42 main       SimpleEven INFO   Registered method listener EventHandler#onChannelMessage
20-02-2022 13:22:42 main       SimpleEven INFO   Registered method listener EventHandler#onUserState
20-02-2022 13:22:42 main       SimpleEven INFO   Registered method listener EventHandler#onChatModeration
20-02-2022 13:22:42 main       StayHydrat INFO   Checking live status for: []
20-02-2022 13:22:42 ReadingThr EventHandl INFO   [USERSTATE][duncte123][DuncteBot] [EVERYONE]
20-02-2022 13:22:42 ReadingThr EventHandl INFO   Adding listener for moderation events in duncte123
20-02-2022 13:22:42 ReadingThr EventHandl INFO   [USERSTATE][crrool][DuncteBot] [EVERYONE, VIP]
20-02-2022 13:22:42 ReadingThr EventHandl INFO   Adding listener for moderation events in crrool
20-02-2022 13:22:52 ReadingThr EventHandl INFO   [duncte123][EVERYONE, SUBSCRIBER, MODERATOR, BROADCASTER] duncte123: !!hangman cheat
20-02-2022 13:22:52 ReadingThr EventHandl INFO   [USERSTATE][duncte123][DuncteBot] [EVERYONE]
20-02-2022 13:22:52 ReadingThr EventHandl INFO   Adding listener for moderation events in duncte123
20-02-2022 13:22:58 ReadingThr EventHandl INFO   [crrool][EVERYONE, SUBSCRIBER, FOUNDER, MODERATOR] bobchao87: I'ma get ready for bed. crroolLurk

Environment

Build Configuration

plugins {
    java
    application
    id("com.github.johnrengelman.shadow") version "7.1.2"
}

group = "com.dunctebot"
version = "1.0-SNAPSHOT"

java {
    sourceCompatibility = JavaVersion.VERSION_16
    targetCompatibility = JavaVersion.VERSION_16
}

application {
    mainClass.set("com.dunctebot.twitch.Main")
}

repositories {
    mavenCentral()
}

dependencies {
    implementation(group = "mysql", name = "mysql-connector-java", version = "8.0.27")
    implementation(group = "com.fasterxml.jackson.datatype", name = "jackson-datatype-jsr310", version = "2.12.4")
    implementation(group = "ch.qos.logback", name = "logback-classic", version = "1.2.9")

    implementation(group = "com.github.twitch4j", name = "twitch4j", version = "1.8.0")

    implementation(group = "com.squareup.okhttp3", name = "okhttp", version = "3.14.9")
    implementation("net.sf.trove4j:trove4j:3.0.3")
}

tasks {
    compileJava {
        // options.compilerArgs.add("--enable-preview")
        options.isIncremental = true
    }
    wrapper {
        gradleVersion = "7.2"
        distributionType = Wrapper.DistributionType.ALL
    }
    shadowJar {
        archiveClassifier.set("")
    }
}

Possible Solution

No response

Additional Context/Screenshots

PhilippHeuer commented 2 years ago

To send whispers make sure your chat token has the whispers:edit scope.

Whispers send from non known/verified bot accounts will be evaluated by a spam classifier and might be dropped. You can request known/verified status for your bot here: https://dev.twitch.tv/limit-increase

Responding to whispers usually works a lot better, initiating contact from the bot isn't very succesful in general. Whispers might be dropped even on known/verified bot accounts, do not expect bot whispers to work reliably.

duncte123 commented 2 years ago

Thanks for the info! It would be nice if that scope was also documented in the library's documentation https://twitch4j.github.io/docs/chat/send-private-message/