C
C#2y ago
quit

✅ Need help fixing CallbackData

[TelegramCommand("ping", false, false)]
public static async Task Ping(Update update, List<string> args)
{
// Create a new inline keyboard button with the text "Ping" and the callback data "ping"
var button = new InlineKeyboardButton
{
Text = "Ping",
CallbackData = "ping"
};

// Create a new inline keyboard markup with the button we just created
var keyboard = new InlineKeyboardMarkup(new[] { new[] { button } });

// Send a message with the text ":robot: Bot is online" and the inline keyboard markup we just created
await Telegram.client.SendMessageAsync(update.Message.Chat.Id, ":robot: Bot is online", replyMarkup: keyboard);
}
[TelegramCommand("ping", false, false)]
public static async Task Ping(Update update, List<string> args)
{
// Create a new inline keyboard button with the text "Ping" and the callback data "ping"
var button = new InlineKeyboardButton
{
Text = "Ping",
CallbackData = "ping"
};

// Create a new inline keyboard markup with the button we just created
var keyboard = new InlineKeyboardMarkup(new[] { new[] { button } });

// Send a message with the text ":robot: Bot is online" and the inline keyboard markup we just created
await Telegram.client.SendMessageAsync(update.Message.Chat.Id, ":robot: Bot is online", replyMarkup: keyboard);
}
41 Replies
quit
quitOP2y ago
error
[TELEGRAM] CallbackQuery: ping Unhandled exception. System.IndexOutOfRangeException: Index was outside the bounds of the array. at Estate_Example.Telegram.HandleUpdate(Update update) in C:\Users\B\Downloads\Telegram Desktop\Estate Example\Estate Example\Telegram.cs:line 93 at Estate_Example.Telegram.<>c__DisplayClass5_0.<PollingThread>b__0() in C:\Users\B\Downloads\Telegram Desktop\Estate Example\Estate Example\Telegram.cs:line 68 at System.Threading.Thread.StartCallback()
[TELEGRAM] CallbackQuery: ping Unhandled exception. System.IndexOutOfRangeException: Index was outside the bounds of the array. at Estate_Example.Telegram.HandleUpdate(Update update) in C:\Users\B\Downloads\Telegram Desktop\Estate Example\Estate Example\Telegram.cs:line 93 at Estate_Example.Telegram.<>c__DisplayClass5_0.<PollingThread>b__0() in C:\Users\B\Downloads\Telegram Desktop\Estate Example\Estate Example\Telegram.cs:line 68 at System.Threading.Thread.StartCallback()
phaseshift
phaseshift2y ago
Is telegram.cs your code file?
quit
quitOP2y ago
Yes.
quit
quitOP2y ago
phaseshift
phaseshift2y ago
Well what's line 93 I bet it has square brackets It's going to be the messageid line, isn't it?
quit
quitOP2y ago
phaseshift
phaseshift2y ago
The line numbers don't match up But it's probably the messageid line. Maybe there is no : in the string
quit
quitOP2y ago
But the error msg both have to do with Callbackdata
quit
quitOP2y ago
quit
quitOP2y ago
quit
quitOP2y ago
case UpdateType.CallbackQuery:
Console.WriteLine("[TELEGRAM] CallbackQuery: " + update.CallbackQuery.Data);
var query = update.CallbackQuery;
string[] data = query.Data.Split(':');
if (data.Length != 2) return; // return if delimiter not found
string querydata = data[0];
string messageid = data[1];
try { Telegram.client.AnswerCallbackQuery(query.Id); } catch { }
HandleCommand(update, "", new List<string>() { messageid }, querydata);
break;
case UpdateType.CallbackQuery:
Console.WriteLine("[TELEGRAM] CallbackQuery: " + update.CallbackQuery.Data);
var query = update.CallbackQuery;
string[] data = query.Data.Split(':');
if (data.Length != 2) return; // return if delimiter not found
string querydata = data[0];
string messageid = data[1];
try { Telegram.client.AnswerCallbackQuery(query.Id); } catch { }
HandleCommand(update, "", new List<string>() { messageid }, querydata);
break;
maybe? I can try this 1 second it printed in cmd prompt
[TELEGRAM] CallbackQuery: ping
[TELEGRAM] CallbackQuery: ping
quit
quitOP2y ago
quit
quitOP2y ago
but nothing printed.
quit
quitOP2y ago
quit
quitOP2y ago
now its just loading
phaseshift
phaseshift2y ago
What are you confused about?
quit
quitOP2y ago
it should be printing right>
quit
quitOP2y ago
phaseshift
phaseshift2y ago
Printing what?
quit
quitOP2y ago
"ping" because callback?
phaseshift
phaseshift2y ago
Where are you sending ping in callback? You exit early
quit
quitOP2y ago
Nono I do /ping in telegram it shows the button when i click the button nothing happens just shows the callback in cmd prompt
phaseshift
phaseshift2y ago
Yeah, because you exit early
quit
quitOP2y ago
not printing in telegram why so
phaseshift
phaseshift2y ago
Thats what 'return' does
quit
quitOP2y ago
[TelegramCommand("ping", false, false)]
public static async Task Ping(Update update, List<string> args)
{
// Create a new inline keyboard button with the text "Ping" and the callback data "ping"
var button = new InlineKeyboardButton
{
Text = "Ping",
CallbackData = "ping"
};

// Create a new inline keyboard markup with the button we just created
var keyboard = new InlineKeyboardMarkup(new[] { new[] { button } });

// Send a message with the text "🤖 Bot is online" and the inline keyboard markup we just created
Telegram.client.SendMessage(update.Message.Chat.Id, "🤖 Bot is online", replyMarkup: keyboard);
[TelegramCommand("ping", false, false)]
public static async Task Ping(Update update, List<string> args)
{
// Create a new inline keyboard button with the text "Ping" and the callback data "ping"
var button = new InlineKeyboardButton
{
Text = "Ping",
CallbackData = "ping"
};

// Create a new inline keyboard markup with the button we just created
var keyboard = new InlineKeyboardMarkup(new[] { new[] { button } });

// Send a message with the text "🤖 Bot is online" and the inline keyboard markup we just created
Telegram.client.SendMessage(update.Message.Chat.Id, "🤖 Bot is online", replyMarkup: keyboard);
but this is the command? so do return after?
phaseshift
phaseshift2y ago
That obviously happens, correct?
quit
quitOP2y ago
Sure
phaseshift
phaseshift2y ago
So... The problem is not there Like you just changed some code in the call back so it does nothing now
quit
quitOP2y ago
well theres no error?
phaseshift
phaseshift2y ago
And you're asking why the call back doesn't do anything?
quit
quitOP2y ago
it just prints ping
HowNiceOfYou
HowNiceOfYou2y ago
pong
quit
quitOP2y ago
[TELEGRAM] CallbackQuery: ping? instead of printing ping in telegram
phaseshift
phaseshift2y ago
Why would it send anything to telegram client You don't call anything to make it
quit
quitOP2y ago
Telegram.client.SendMessage(update.Message.Chat.Id, ":robot: Bot is online", replyMarkup: keyboard); so what would it be than to send message
phaseshift
phaseshift2y ago
That one is already sent You've shown it
quit
quitOP2y ago
AH [TelegramCommand("BUTTON:Ping", false, false)] public static async Task Ping(Update update, List<string> args) => Console.WriteLine("[ESTATE] " + await Estate.TriggerEvent("Ping", args[0])); nvm
Nox
Nox2y ago
@HowNiceOfYou my guy You seem to actually have a brain in that head of yours judging by your questions and everything, but self-botting is against Discord's Terms of Service Please disable it if you wish to participate in this server. I'll check again in a day and if not, you will be removed.
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
quit
quitOP2y ago
o
[TelegramCommand("ping", false, false, "BUTTON:Ping")]
public static async Task Ping(Update update, List<string> args)
{
// Create a new inline keyboard button with the text "Ping" and the callback data "ping"
var button = new InlineKeyboardButton
{
Text = "Ping",
CallbackData = "ping"
};

// Create a new inline keyboard markup with the button we just created
var keyboard = new InlineKeyboardMarkup(new[] { new[] { button } });

// Send a message with the text "🤖 Bot is online" and the inline keyboard markup we just created
await Telegram.client.SendMessageAsync(update.Message.Chat.Id, "🤖 Bot is online", replyMarkup: keyboard);
}
[TelegramCommand("ping", false, false, "BUTTON:Ping")]
public static async Task Ping(Update update, List<string> args)
{
// Create a new inline keyboard button with the text "Ping" and the callback data "ping"
var button = new InlineKeyboardButton
{
Text = "Ping",
CallbackData = "ping"
};

// Create a new inline keyboard markup with the button we just created
var keyboard = new InlineKeyboardMarkup(new[] { new[] { button } });

// Send a message with the text "🤖 Bot is online" and the inline keyboard markup we just created
await Telegram.client.SendMessageAsync(update.Message.Chat.Id, "🤖 Bot is online", replyMarkup: keyboard);
}
tried this but it only gives a callback to console instead of sending to the bot y
Want results from more Discord servers?
Add your server