Comments (9)
I'll update the library do use a std::string, since everything else in my library uses std::string, it should be a very simple change.
from sleepy-discord.
This isn't a bug or an issue with startsWith, you just need to use a char*. It's better to use a std::string with the function std::string::data(). For example
std::string startMessage = "ssssss";
if (message.startsWith(startMessage.data())) {
//code
}
However, I'm most likely going to rewrite this function to use a std::string instead as this is most likely a function made when this library was a c library.
also you should learn the difference between a char and a char*. No offense because you are new to this, just saying that it's something you should know because it's will be very good to know when working with C++.
from sleepy-discord.
then your example is incorrect
#include "sleepy_discord/websocketpp_websocket.h"
class myClientClass : public SleepyDiscord::DiscordClient {
public:
using SleepyDiscord::DiscordClient::DiscordClient;
void onMessage(SleepyDiscord::Message message) {
if (message.startsWith("whcg hello"))
sendMessage(message.channelID, "Hello " + message.author.username);
}
};
int main() {
myClientClass client("token", 2);
client.run();
}
from sleepy-discord.
No, it's correct. Because that is a char* or a string literal. Or are you saying that you can't get the example to compile?
from sleepy-discord.
yes i tried but did not work
from sleepy-discord.
well I'm going to guess that you used a char, correct? If so, that would make sense why it wouldn't work, it's expecting a pointer to a array of chars. If you are talking about the example, can you give me the error with the error code and line number?
from sleepy-discord.
I try to do as you do, but it does not work.
C2664 Line:7
E0167 Line:7
message.h
bool startsWith(char* test);
C2664 line: 52
from sleepy-discord.
Oh I see, I made a mistake since std::string::data() returns a const char* instead of a char*. I'm not sure that this will work but do something like const_cast<char*>(startMessage.c_str())
from sleepy-discord.
thanks I am new to c ++ and I think that I can learn by writing a simple bot in the discord
from sleepy-discord.
Related Issues (20)
- How to reply to a message or mention the message author? HOT 4
- how to get user input? HOT 1
- Code error? HOT 3
- createChannel doesn't exsit, and createTextChannel gives errors on use. HOT 1
- [ASK] HOW TO REPLY A MESSAGE? HOT 1
- Issue 4 HOT 4
- LNK1181 cannot open input file 'cpr.lib' HOT 6
- Error 5002: Could not get the gateway HOT 8
- [ASK]sendMessage() HOT 1
- [ASK]How to receive modified messages
- Error 429 5005 HOT 3
- Why is there an error? HOT 2
- Conan support
- Is it possible to use only curl to perfome requests and etc without websocket and etc? HOT 3
- Cannot build for 3DS
- Error 5002: Could not get the gateway on Ubuntu
- Downloading via vcpkg HOT 2
- user-bot HOT 1
- SLEEPY_VCPKG confusion HOT 3
- ‘memset’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
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 sleepy-discord.