Comments (9)
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.
Hey, can you please show some of your code?
from javacord.
if define multiple bot not work like
DiscrodBot bot1,bot2
from javacord.
The bot is in the server you are trying to send the message to, right?
from javacord.
Yes. send to message to Channel
only 1 bot works.
if define 2, or more then null pointexception come out
from javacord.
What the...
wait i will give you example code OK?
from javacord.
`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.
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.
No answer since august
from javacord.
Related Issues (20)
- Move from deprecated channel_id to new interaction channel field
- Couldn't handle packet of type VOICE_STATE_UPDATE
- Add voice message support to text channel
- Add super reactions
- Slash Commands issue HOT 11
- Replacement/just removal and deprecation of `getDiscriminatedName ` HOT 8
- Add role flags HOT 1
- Add attachment flags HOT 1
- Add the message author id to message reaction events HOT 1
- Add user avatar decorations
- SlashCommandOptionChoice#getLongValue returns a empty optional despite a long value being present on DAPI HOT 2
- `ServerThreadChannelCreateListener` dispatching twice.
- Parameters are ignored when requesting archived threads
- Look through the code for non thread safe collections
- Add default select menu values HOT 1
- Add support for premium app subscriptions
- Add resolved field to message components
- Fix Embed* implementation methods returning null instead of optional
- Continuous switching between the voice channels.
- Ability to set message flags for any message to send (not only for interaction messages)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from javacord.