GithubHelp home page GithubHelp logo

Comments (9)

Treescrub avatar Treescrub commented on May 27, 2024 2

If you do:
DiscordBot bot1,bot2;
It will of course throw a NullPointerException if you try to call connect() because it will not have been constructed

from javacord.

Bastian avatar Bastian commented on May 27, 2024

Hey, can you please show some of your code?

from javacord.

code1ine avatar code1ine commented on May 27, 2024

https://github.com/poop-code/PokemonGo-Web-Crawler/blob/master/src/main/java/org/jh/pogo/crawler/bot/DiscordBot.java

if define multiple bot not work like
DiscrodBot bot1,bot2

from javacord.

Treescrub avatar Treescrub commented on May 27, 2024

The bot is in the server you are trying to send the message to, right?

from javacord.

code1ine avatar code1ine commented on May 27, 2024

Yes. send to message to Channel
only 1 bot works.
if define 2, or more then null pointexception come out

from javacord.

code1ine avatar code1ine commented on May 27, 2024

What the...
wait i will give you example code OK?

from javacord.

code1ine avatar code1ine commented on May 27, 2024

`package testjavacord;

import java.io.File;

import com.google.common.util.concurrent.FutureCallback;

import de.btobastian.javacord.DiscordAPI;
import de.btobastian.javacord.Javacord;

public class DiscordTester {

private final static String TOKEN = "tokenval";
private final static String TOKEN2 = "tokenval2";
private final static String channelID4TOKEN = "336438218490000000";
private final static String channelID4TOKEN2 = "3364383390000000000";


public static void main(String[] args) {
	SampleDiscordBot bot1,bot2;
	bot1 = new SampleDiscordBot(TOKEN,channelID4TOKEN);
	bot2 = new SampleDiscordBot(TOKEN2,channelID4TOKEN2);
	bot1.connect();
	bot2.connect();

}

}

class SampleDiscordBot {
private String token;
private String channel;

private DiscordAPI 	api;


public SampleDiscordBot(String token,String channel) {
	this.token = token;
	this.channel = channel;
	
}//end Discord()


public void connect() {
	
	
	api = Javacord.getApi(token, true);
	
	
	api.connect(new FutureCallback<DiscordAPI>() {

		
		public void onFailure(Throwable t) {
			
			t.getStackTrace();
			
		}//end onFailure

		
		public void onSuccess(DiscordAPI api) {

			
			api.getChannelById(channel).sendMessage("SUCCESS");
			
		}//end onSuccess

		
	});//end connect(FutureCallback)
	
}//end connect()




public void message(String msg ,String channel) {

	
	if(msg == null && channel ==null) {
		return;
	}
	
	api.getChannelById(channel).sendMessage(msg);

}


public void message(String msg, File file ,String channel) {

	
	if(msg == null && channel ==null) {
		return;
	}
	
	if(file != null) {
		if(!file.exists()) {
			//File not exists
			
			
		}else {
			api.getChannelById(channel).sendFile(file);
		}//if file.exists
		
	}//if file not null

	

	api.getChannelById(channel).sendMessage(msg);

	file = null;
}

}
`

----DEBUG----
07:54:54.570 [pool-3-thread-1] DEBUG de.btobastian.javacord.ImplDiscordAPI - Checking token ************************************************************XDM
07:54:54.567 [pool-2-thread-1] DEBUG de.btobastian.javacord.ImplDiscordAPI - Checking token ************************************************************awE
07:54:55.058 [pool-3-thread-1] DEBUG de.btobastian.javacord.ImplDiscordAPI - Checked token ************************************************************XDM (valid: true)
07:54:55.059 [pool-3-thread-1] DEBUG de.btobastian.javacord.ImplDiscordAPI - Requesting gateway (token: ************************************************************XDM)
07:54:55.059 [pool-2-thread-1] DEBUG de.btobastian.javacord.ImplDiscordAPI - Checked token ************************************************************awE (valid: true)
07:54:55.059 [pool-2-thread-1] DEBUG de.btobastian.javacord.ImplDiscordAPI - Requesting gateway (token: ************************************************************awE)
07:54:55.069 [pool-3-thread-1] DEBUG de.btobastian.javacord.ImplDiscordAPI - Requested gateway wss://gateway.discord.gg (token: ************************************************************XDM)
07:54:55.070 [pool-2-thread-1] DEBUG de.btobastian.javacord.ImplDiscordAPI - Requested gateway wss://gateway.discord.gg (token: ************************************************************awE)
07:54:55.635 [ReadingThread] DEBUG de.btobastian.javacord.utils.DiscordWebsocketAdapter - Sending identify packet
07:54:55.635 [ReadingThread] DEBUG de.btobastian.javacord.utils.DiscordWebsocketAdapter - Sending identify packet
07:54:55.640 [ReadingThread] DEBUG de.btobastian.javacord.utils.DiscordWebsocketAdapter - Received HELLO packet
07:54:55.640 [ReadingThread] DEBUG de.btobastian.javacord.utils.DiscordWebsocketAdapter - Received HELLO packet
07:54:56.006 [Timer-0] DEBUG de.btobastian.javacord.utils.DiscordWebsocketAdapter - Sent heartbeat (interval: 41250)
07:54:56.008 [ReadingThread] DEBUG de.btobastian.javacord.utils.DiscordWebsocketAdapter - Received READY packet
07:54:56.147 [ReadingThread] DEBUG de.btobastian.javacord.utils.DiscordWebsocketAdapter - Received READY packet
07:54:56.147 [Timer-1] DEBUG de.btobastian.javacord.utils.DiscordWebsocketAdapter - Sent heartbeat (interval: 41250)
7. 27, 2017 7:54:58 AM com.google.common.util.concurrent.AbstractFuture executeListener
FATAL: RuntimeException while executing runnable com.google.common.util.concurrent.Futures$4@1bd2fe53 with executor MoreExecutors.directExecutor()
java.lang.NullPointerException
at testjavacord.SampleDiscordBot$1.onSuccess(DiscordTester.java:62)
at testjavacord.SampleDiscordBot$1.onSuccess(DiscordTester.java:1)
at com.google.common.util.concurrent.Futures$4.run(Futures.java:1132)
at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:435)
at com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:900)
at com.google.common.util.concurrent.AbstractFuture.complete(AbstractFuture.java:811)
at com.google.common.util.concurrent.AbstractFuture.set(AbstractFuture.java:653)
at com.google.common.util.concurrent.TrustedListenableFutureTask$TrustedFutureInterruptibleTask.runInterruptibly(TrustedListenableFutureTask.java:111)
at com.google.common.util.concurrent.InterruptibleTask.run(InterruptibleTask.java:58)
at com.google.common.util.concurrent.TrustedListenableFutureTask.run(TrustedListenableFutureTask.java:75)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

07:55:00.011 [pool-2-thread-2] DEBUG de.btobastian.javacord.entities.impl.ImplChannel - Trying to send message in channel korea100 (id: 336438218490642442) (content: "SUCCESS", tts: false)
07:55:00.265 [pool-2-thread-2] DEBUG de.btobastian.javacord.entities.impl.ImplChannel - Sent message in channel korea100 (id: 336438218490642442) (content: "SUCCESS", tts: false)

if only one define discordbot gonna works. but 2 and more null point exception like this.

from javacord.

Bastian avatar Bastian commented on May 27, 2024

Having multiple bots should normaly not cause any trouble even though I never tested it.
Can you please try adding a few seconds delay between the creation of the bots and also check if the ServerJoinListener is getting called?

from javacord.

Bastian avatar Bastian commented on May 27, 2024

No answer since august

from javacord.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.